Skip to content

Commit aae2833

Browse files
committed
chore(attrs): standardize on attrs package import
`attr` is the legacy module name, containing `s` and `ib`, which are not exposed through `attrs` which also matches the package name. For reasoing, see the previous commit.
1 parent 7e9f151 commit aae2833

File tree

13 files changed

+83
-79
lines changed

13 files changed

+83
-79
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ select = [
9090
"T10", # flake8-debugger
9191
"T20", # flake8-print
9292
"TC", # flake8-type-checking
93+
"TID251", # flake8-tidy-imports; banned-api
9394
"TRY", # tryceratops
9495
"UP", # pyupgrade
9596
"W", # pycodestyle (warnings)
@@ -144,6 +145,9 @@ fixture-parentheses = false
144145
mark-parentheses = false
145146
parametrize-names-type = "csv"
146147

148+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
149+
"attr".msg = "Use `attrs` (with an 's') instead"
150+
147151
[tool.pytest.ini_options]
148152
addopts = "--cov=unblob --cov=tests --cov-branch --cov-fail-under=90"
149153
norecursedirs = """

tests/test_finder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import attr
1+
import attrs
22
import pytest
33
from pyperscan import Scan
44

@@ -233,4 +233,4 @@ def test_search_chunks(content, expected_chunks, task_result):
233233

234234
assert len(chunks) == len(expected_chunks)
235235
for expected_chunk, chunk in zip(expected_chunks, chunks):
236-
assert attr.evolve(chunk, id="") == attr.evolve(expected_chunk, id="")
236+
assert attrs.evolve(chunk, id="") == attrs.evolve(expected_chunk, id="")

tests/test_processing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from statistics import mean
77
from typing import Optional, TypeVar
88

9-
import attr
9+
import attrs
1010
import pytest
1111

1212
from unblob import handlers
@@ -54,7 +54,7 @@ def assert_same_chunks(expected, actual, explanation=None):
5454
"""Assert ignoring the chunk.id-s."""
5555
assert len(expected) == len(actual), explanation
5656
for e, a in zip(expected, actual):
57-
assert attr.evolve(e, id="") == attr.evolve(a, id=""), explanation
57+
assert attrs.evolve(e, id="") == attrs.evolve(a, id=""), explanation
5858

5959

6060
@pytest.mark.parametrize(

unblob/dependencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import shutil
22

3-
import attr
3+
import attrs
44

55
from .models import DirectoryHandlers, Handlers
66

77

8-
@attr.define
8+
@attrs.define
99
class Dependency:
1010
command: str
1111
is_installed: bool

unblob/handlers/archive/cpio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import Path
55
from typing import Optional
66

7-
import attr
7+
import attrs
88
from structlog import get_logger
99

1010
from ...file_utils import (
@@ -110,7 +110,7 @@
110110
"""
111111

112112

113-
@attr.define
113+
@attrs.define
114114
class CPIOEntry:
115115
start_offset: int
116116
size: int

unblob/handlers/archive/qnap/qnap_nas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from typing import Optional
44

5-
import attr
5+
import attrs
66
from pyperscan import Flag, Pattern, Scan, StreamDatabase
77
from structlog import get_logger
88

@@ -36,7 +36,7 @@
3636
]
3737

3838

39-
@attr.define
39+
@attrs.define
4040
class QTSSearchContext:
4141
start_offset: int
4242
file: File

unblob/handlers/compression/bzip2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22

3-
import attr
3+
import attrs
44
from pyperscan import Flag, Pattern, Scan, StreamDatabase
55
from structlog import get_logger
66

@@ -63,7 +63,7 @@ def build_stream_end_scan_db(pattern_list):
6363
parser = StructParser(C_DEFINITIONS)
6464

6565

66-
@attr.define
66+
@attrs.define
6767
class Bzip2SearchContext:
6868
start_offset: int
6969
file: File

unblob/handlers/compression/xz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io
22
from typing import Optional
33

4-
import attr
4+
import attrs
55
from pyperscan import Flag, Pattern, Scan, StreamDatabase
66
from structlog import get_logger
77

@@ -61,7 +61,7 @@ def build_stream_end_scan_db(pattern_list):
6161
hyperscan_stream_end_magic_db = build_stream_end_scan_db(STREAM_END_MAGIC_PATTERNS)
6262

6363

64-
@attr.define
64+
@attrs.define
6565
class XZSearchContext:
6666
start_offset: int
6767
file: File

unblob/handlers/executable/elf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Optional
55

6-
import attr
6+
import attrs
77
import lief
88
from structlog import get_logger
99

@@ -29,7 +29,7 @@
2929
KERNEL_INIT_DATA_SECTION = ".init.data"
3030

3131

32-
@attr.define(repr=False)
32+
@attrs.define(repr=False)
3333
class ElfChunk(ValidChunk):
3434
def extract(self, inpath: Path, outdir: Path):
3535
# ELF file extraction is special in that in the general case no new files are extracted, thus

unblob/handlers/filesystem/yaffs.py

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

9-
import attr
9+
import attrs
1010
from structlog import get_logger
1111
from treelib import Tree
1212
from treelib.exceptions import NodeIDAbsentError
@@ -141,59 +141,59 @@ class YaffsObjectType(IntEnum):
141141
SPECIAL = 5
142142

143143

144-
@attr.define
144+
@attrs.define
145145
class YAFFSChunk:
146146
chunk_id: int
147147
offset: int
148148
byte_count: int
149149
object_id: int
150150

151151

152-
@attr.define
152+
@attrs.define
153153
class YAFFS1Chunk(YAFFSChunk):
154154
serial: int
155155
ecc: bytes
156156
page_status: int
157157
block_status: int
158158

159159

160-
@attr.define
160+
@attrs.define
161161
class YAFFS2Chunk(YAFFSChunk):
162162
seq_number: int
163163

164164

165-
@attr.define
165+
@attrs.define
166166
class YAFFSFileVar:
167167
file_size: int
168168
stored_size: int
169169
shrink_size: int
170170
top_level: int
171171

172172

173-
@attr.define
173+
@attrs.define
174174
class YAFFSConfig:
175175
endianness: Endian
176176
page_size: int
177177
spare_size: int
178178
ecc: bool
179179

180180

181-
@attr.define
181+
@attrs.define
182182
class YAFFSEntry:
183183
object_type: YaffsObjectType
184184
object_id: int
185185
parent_obj_id: int
186-
sum_no_longer_used: int = attr.ib(default=0)
187-
name: str = attr.ib(default="")
188-
alias: str = attr.ib(default="")
189-
equiv_id: int = attr.ib(default=0)
190-
file_size: int = attr.ib(default=0)
191-
st_mode: int = attr.ib(default=0)
192-
st_uid: int = attr.ib(default=0)
193-
st_gid: int = attr.ib(default=0)
194-
st_atime: int = attr.ib(default=0)
195-
st_mtime: int = attr.ib(default=0)
196-
st_ctime: int = attr.ib(default=0)
186+
sum_no_longer_used: int = attrs.field(default=0)
187+
name: str = attrs.field(default="")
188+
alias: str = attrs.field(default="")
189+
equiv_id: int = attrs.field(default=0)
190+
file_size: int = attrs.field(default=0)
191+
st_mode: int = attrs.field(default=0)
192+
st_uid: int = attrs.field(default=0)
193+
st_gid: int = attrs.field(default=0)
194+
st_atime: int = attrs.field(default=0)
195+
st_mtime: int = attrs.field(default=0)
196+
st_ctime: int = attrs.field(default=0)
197197

198198
def __lt__(self, other):
199199
return self.object_id < other.object_id
@@ -208,18 +208,18 @@ def __str__(self):
208208
return f"{self.object_id}: {self.name}"
209209

210210

211-
@attr.define(kw_only=True)
211+
@attrs.define(kw_only=True)
212212
class YAFFS2Entry(YAFFSEntry):
213-
chksum: int = attr.ib(default=0)
214-
st_rdev: int = attr.ib(default=0)
215-
win_ctime: list[int] = attr.ib(default=[])
216-
win_mtime: list[int] = attr.ib(default=[])
217-
inband_shadowed_obj_id: int = attr.ib(default=0)
218-
inband_is_shrink: int = attr.ib(default=0)
219-
reserved: list[int] = attr.ib(default=[])
220-
shadows_obj: int = attr.ib(default=0)
221-
is_shrink: int = attr.ib(default=0)
222-
filehead: YAFFSFileVar = attr.ib(default=None)
213+
chksum: int = attrs.field(default=0)
214+
st_rdev: int = attrs.field(default=0)
215+
win_ctime: list[int] = attrs.field(default=[])
216+
win_mtime: list[int] = attrs.field(default=[])
217+
inband_shadowed_obj_id: int = attrs.field(default=0)
218+
inband_is_shrink: int = attrs.field(default=0)
219+
reserved: list[int] = attrs.field(default=[])
220+
shadows_obj: int = attrs.field(default=0)
221+
is_shrink: int = attrs.field(default=0)
222+
filehead: YAFFSFileVar = attrs.field(default=None)
223223

224224

225225
def iterate_over_file(

0 commit comments

Comments
 (0)