Skip to content

Commit 7e9f151

Browse files
committed
chore(ruff): fix false positive function-call-in-dataclass-default-argument lints
The following lints are false positive, but highlight a problem: 178 | @attrs.define 179 | class MultiFile(Blob): 180 | name: str = attr.field(kw_only=True) | ^^^^^^^^^^^^^^^^^^^^^^^^ RUF009 181 | paths: list[Path] = attr.field(kw_only=True) | unblob/models.py:181:25: RUF009 Do not perform function call `attr.field` in dataclass defaults | 179 | class MultiFile(Blob): 180 | name: str = attr.field(kw_only=True) 181 | paths: list[Path] = attr.field(kw_only=True) | ^^^^^^^^^^^^^^^^^^^^^^^^ RUF009 182 | 183 | handler: "DirectoryHandler" = attr.ib(init=False, eq=False) | The issue is that we are using both `attrs` and legacy `attr` module imports in the same scope. Fixing these also introduce invalid `attrs.ib` calls as well, which also has to be fixed
1 parent 13477e9 commit 7e9f151

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

unblob/models.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pathlib import Path
77
from typing import Optional, TypeVar
88

9-
import attr
109
import attrs
1110
from structlog import get_logger
1211

@@ -31,22 +30,22 @@
3130
#
3231

3332

34-
@attr.define(frozen=True)
33+
@attrs.define(frozen=True)
3534
class Task:
3635
path: Path
3736
depth: int
3837
blob_id: str
39-
is_multi_file: bool = attr.field(default=False)
38+
is_multi_file: bool = attrs.field(default=False)
4039

4140

42-
@attr.define
41+
@attrs.define
4342
class Blob:
44-
id: str = attr.field(
43+
id: str = attrs.field(
4544
factory=new_id,
4645
)
4746

4847

49-
@attr.define
48+
@attrs.define
5049
class Chunk(Blob):
5150
"""File chunk, have start and end offset, but still can be invalid.
5251
@@ -56,10 +55,10 @@ class Chunk(Blob):
5655
b[c.start_offset:c.end_offset]
5756
"""
5857

59-
start_offset: int = attr.field(kw_only=True)
58+
start_offset: int = attrs.field(kw_only=True)
6059
"""The index of the first byte of the chunk"""
6160

62-
end_offset: int = attr.field(kw_only=True)
61+
end_offset: int = attrs.field(kw_only=True)
6362
"""The index of the first byte after the end of the chunk"""
6463

6564
file: Optional[File] = None
@@ -101,12 +100,12 @@ def __repr__(self) -> str:
101100
return self.range_hex
102101

103102

104-
@attr.define(repr=False)
103+
@attrs.define(repr=False)
105104
class ValidChunk(Chunk):
106105
"""Known to be valid chunk of a File, can be extracted with an external program."""
107106

108-
handler: "Handler" = attr.ib(init=False, eq=False)
109-
is_encrypted: bool = attr.ib(default=False)
107+
handler: "Handler" = attrs.field(init=False, eq=False)
108+
is_encrypted: bool = attrs.field(default=False)
110109

111110
def extract(self, inpath: Path, outdir: Path) -> Optional["ExtractResult"]:
112111
if self.is_encrypted:
@@ -131,7 +130,7 @@ def as_report(self, extraction_reports: list[Report]) -> ChunkReport:
131130
)
132131

133132

134-
@attr.define(repr=False)
133+
@attrs.define(repr=False)
135134
class UnknownChunk(Chunk):
136135
r"""Gaps between valid chunks or otherwise unknown chunks.
137136
@@ -152,7 +151,7 @@ def as_report(self, randomness: Optional[RandomnessReport]) -> UnknownChunkRepor
152151
)
153152

154153

155-
@attr.define(repr=False)
154+
@attrs.define(repr=False)
156155
class PaddingChunk(Chunk):
157156
r"""Gaps between valid chunks or otherwise unknown chunks.
158157
@@ -177,10 +176,10 @@ def as_report(
177176

178177
@attrs.define
179178
class MultiFile(Blob):
180-
name: str = attr.field(kw_only=True)
181-
paths: list[Path] = attr.field(kw_only=True)
179+
name: str = attrs.field(kw_only=True)
180+
paths: list[Path] = attrs.field(kw_only=True)
182181

183-
handler: "DirectoryHandler" = attr.ib(init=False, eq=False)
182+
handler: "DirectoryHandler" = attrs.field(init=False, eq=False)
184183

185184
def extract(self, outdir: Path) -> Optional["ExtractResult"]:
186185
return self.handler.extract(self.paths, outdir)
@@ -198,11 +197,11 @@ def as_report(self, extraction_reports: list[Report]) -> MultiFileReport:
198197
ReportType = TypeVar("ReportType", bound=Report)
199198

200199

201-
@attr.define
200+
@attrs.define
202201
class TaskResult:
203202
task: Task
204-
reports: list[Report] = attr.field(factory=list)
205-
subtasks: list[Task] = attr.field(factory=list)
203+
reports: list[Report] = attrs.field(factory=list)
204+
subtasks: list[Task] = attrs.field(factory=list)
206205

207206
def add_report(self, report: Report):
208207
self.reports.append(report)
@@ -214,9 +213,9 @@ def filter_reports(self, report_class: type[ReportType]) -> list[ReportType]:
214213
return [report for report in self.reports if isinstance(report, report_class)]
215214

216215

217-
@attr.define
216+
@attrs.define
218217
class ProcessResult:
219-
results: list[TaskResult] = attr.field(factory=list)
218+
results: list[TaskResult] = attrs.field(factory=list)
220219

221220
@property
222221
def errors(self) -> list[ErrorReport]:
@@ -257,9 +256,9 @@ def get_output_dir(self) -> Optional[Path]:
257256

258257
class _JSONEncoder(json.JSONEncoder):
259258
def default(self, obj):
260-
if attr.has(type(obj)):
259+
if attrs.has(type(obj)):
261260
extend_attr_output = True
262-
attr_output = attr.asdict(obj, recurse=not extend_attr_output)
261+
attr_output = attrs.asdict(obj, recurse=not extend_attr_output)
263262
attr_output["__typename__"] = obj.__class__.__name__
264263
return attr_output
265264

@@ -295,7 +294,7 @@ def __init__(self, *reports: Report):
295294
self.reports: tuple[Report, ...] = reports
296295

297296

298-
@attr.define(kw_only=True)
297+
@attrs.define(kw_only=True)
299298
class ExtractResult:
300299
reports: list[Report]
301300

0 commit comments

Comments
 (0)