Skip to content

Commit abc2ccf

Browse files
Apply and enforce ruff/flake8-bugbear rules (B)
B007 Loop control variable not used within loop body B028 No explicit `stacklevel` keyword argument found B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling B905 `zip()` without an explicit `strict=` parameter
1 parent b0fd139 commit abc2ccf

File tree

11 files changed

+18
-17
lines changed

11 files changed

+18
-17
lines changed

adhoc/blosc_memleak_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
codec = numcodecs.Blosc()
99
data = np.arange(int(sys.argv[1]))
10-
for i in range(int(sys.argv[2])):
10+
for _i in range(int(sys.argv[2])):
1111
enc = codec.encode(data)
1212
dec = codec.decode(enc)
1313
arr = np.frombuffer(dec, dtype=data.dtype)

numcodecs/tests/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def assert_array_items_equal(res, arr):
200200
# and values
201201
arr = arr.ravel().tolist()
202202
res = res.ravel().tolist()
203-
for a, r in zip(arr, res):
203+
for a, r in zip(arr, res, strict=True):
204204
if isinstance(a, np.ndarray):
205205
assert_array_equal(a, r)
206206
elif a != a:

numcodecs/tests/test_lzma.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
try:
1010
# noinspection PyProtectedMember
1111
from numcodecs.lzma import LZMA, _lzma
12-
except ImportError: # pragma: no cover
13-
raise unittest.SkipTest("LZMA not available")
12+
except ImportError as e: # pragma: no cover
13+
raise unittest.SkipTest("LZMA not available") from e
1414

1515

1616
from numcodecs.tests.common import (

numcodecs/tests/test_msgpacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
try:
99
from numcodecs.msgpacks import MsgPack
10-
except ImportError: # pragma: no cover
11-
raise unittest.SkipTest("msgpack not available")
10+
except ImportError as e: # pragma: no cover
11+
raise unittest.SkipTest("msgpack not available") from e
1212

1313

1414
from numcodecs.tests.common import (

numcodecs/tests/test_registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def test_all_classes_registered():
2727
see #346 for more info
2828
"""
2929
missing = set()
30-
for name, submod in inspect.getmembers(numcodecs, inspect.ismodule):
31-
for name, obj in inspect.getmembers(submod):
30+
for _name, submod in inspect.getmembers(numcodecs, inspect.ismodule):
31+
for _name, obj in inspect.getmembers(submod):
3232
if inspect.isclass(obj):
3333
if issubclass(obj, numcodecs.abc.Codec):
3434
if obj.codec_id not in numcodecs.registry.codec_registry:

numcodecs/tests/test_vlen_array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
try:
77
from numcodecs.vlen import VLenArray
8-
except ImportError: # pragma: no cover
9-
raise unittest.SkipTest("vlen-array not available")
8+
except ImportError as e: # pragma: no cover
9+
raise unittest.SkipTest("vlen-array not available") from e
1010
from numcodecs.tests.common import (
1111
check_config,
1212
check_repr,

numcodecs/tests/test_vlen_bytes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
try:
77
from numcodecs.vlen import VLenBytes
8-
except ImportError: # pragma: no cover
9-
raise unittest.SkipTest("vlen-bytes not available")
8+
except ImportError as e: # pragma: no cover
9+
raise unittest.SkipTest("vlen-bytes not available") from e
1010
from numcodecs.tests.common import (
1111
check_config,
1212
check_repr,

numcodecs/tests/test_vlen_utf8.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
try:
99
from numcodecs.vlen import VLenUTF8
10-
except ImportError: # pragma: no cover
11-
raise unittest.SkipTest("vlen-utf8 not available")
10+
except ImportError as e: # pragma: no cover
11+
raise unittest.SkipTest("vlen-utf8 not available") from e
1212
from numcodecs.tests.common import (
1313
check_config,
1414
check_repr,

numcodecs/zfpy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"NumPy version >= 2.0.0 detected. The zfpy library is incompatible with this version of NumPy. "
1818
"Please downgrade to NumPy < 2.0.0 or wait for an update from zfpy.",
1919
UserWarning,
20+
stacklevel=2,
2021
)
2122
else:
2223
with suppress(ImportError):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ environment = { DISABLE_NUMCODECS_AVX2=1, DISABLE_NUMCODECS_SSE2=1 }
134134
line-length = 100
135135

136136
[tool.ruff.lint]
137-
extend-select = [ "RUF" ]
137+
extend-select = [ "B", "RUF" ]
138138
ignore = [ "RUF001" ]
139139

140140
[tool.ruff.format]

0 commit comments

Comments
 (0)