Skip to content

Commit e836f39

Browse files
Apply and enforce more ruff rules (#594)
* Deprecate a couple ruff/pyupgrade rules (UP) * Enforce ruff/flake8-pytest-style rules (PT) * Apply ruff/flake8-pytest-style rule PT006 PT006 Wrong type passed to first argument of `@pytest.mark.parametrize`; expected `tuple` * Apply ruff/flake8-pytest-style rule PT007 PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` * Enforce ruff/flake8-bugbear rules (B) * Apply ruff/flake8-executable rule EXE001 EXE001 Shebang is present but file is not executable * Enforce ruff/pygrep-hooks rules (PGH) * Apply ruff/flake8-simplify rule SIM102 SIM102 Use a single `if` statement instead of nested `if` statements * Apply ruff/flake8-simplify rule SIM105 SIM105 Use `contextlib.suppress(ImportError)` instead of `try`-`except`-`pass` * Apply ruff/flake8-raise rule RSE102 RSE102 Unnecessary parentheses on raised exception * Enforce ruff/flake8-raise rules (RSE)
1 parent 8edd3f9 commit e836f39

File tree

9 files changed

+36
-17
lines changed

9 files changed

+36
-17
lines changed

docs/conf.py

100644100755
File mode changed.

numcodecs/lzma.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import contextlib
2+
13
_lzma = None
24
try:
35
import lzma as _lzma
46
except ImportError: # pragma: no cover
5-
try:
7+
with contextlib.suppress(ImportError):
68
from backports import lzma as _lzma
7-
except ImportError:
8-
pass
99

1010

1111
if _lzma:

numcodecs/registry.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ def get_codec(config):
4242
config = dict(config)
4343
codec_id = config.pop('id', None)
4444
cls = codec_registry.get(codec_id)
45-
if cls is None:
46-
if codec_id in entries:
47-
logger.debug("Auto loading codec '%s' from entrypoint", codec_id)
48-
cls = entries[codec_id].load()
49-
register_codec(cls, codec_id=codec_id)
45+
if cls is None and codec_id in entries:
46+
logger.debug("Auto loading codec '%s' from entrypoint", codec_id)
47+
cls = entries[codec_id].load()
48+
register_codec(cls, codec_id=codec_id)
5049
if cls:
5150
return cls.from_config(config)
5251
raise ValueError(f'codec not available: {codec_id!r}')

numcodecs/tests/test_blosc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_compress_blocksize_default(use_threads):
133133
assert blocksize > 0
134134

135135

136-
@pytest.mark.parametrize('bs', (2**7, 2**8))
136+
@pytest.mark.parametrize('bs', [2**7, 2**8])
137137
def test_compress_blocksize(use_threads, bs):
138138
arr = np.arange(1000, dtype='i4')
139139

@@ -225,7 +225,7 @@ def _decode_worker(enc):
225225
return data
226226

227227

228-
@pytest.mark.parametrize('pool', (Pool, ThreadPool))
228+
@pytest.mark.parametrize('pool', [Pool, ThreadPool])
229229
def test_multiprocessing(use_threads, pool):
230230
data = np.arange(1000000)
231231
enc = _encode_worker(data)

numcodecs/tests/test_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_backwards_compatibility():
5959

6060

6161
@pytest.mark.parametrize(
62-
"input_data, dtype",
62+
('input_data', 'dtype'),
6363
[
6464
([0, 1], None),
6565
([[0, 1], [2, 3]], None),

numcodecs/tests/test_msgpacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_backwards_compatibility():
5656

5757

5858
@pytest.mark.parametrize(
59-
"input_data, dtype",
59+
("input_data", "dtype"),
6060
[
6161
([0, 1], None),
6262
([[0, 1], [2, 3]], None),

numcodecs/tests/test_shuffle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _decode_worker(enc):
8989
return data
9090

9191

92-
@pytest.mark.parametrize('pool', (Pool, ThreadPool))
92+
@pytest.mark.parametrize('pool', [Pool, ThreadPool])
9393
def test_multiprocessing(pool):
9494
data = np.arange(1000000)
9595
enc = _encode_worker(data)

pyproject.toml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,28 @@ environment = { DISABLE_NUMCODECS_AVX2=1, DISABLE_NUMCODECS_SSE2=1 }
137137
line-length = 100
138138

139139
[tool.ruff.lint]
140-
extend-select = [ "B", "I", "RUF", "UP" ]
141-
ignore = [ "RUF001", "UP007" ]
140+
extend-select = [
141+
"B",
142+
"I",
143+
"PGH",
144+
"PT",
145+
"RSE",
146+
"RUF",
147+
"UP",
148+
]
149+
ignore = [
150+
"B028",
151+
"B904",
152+
"PT001",
153+
"PT004", # deprecated
154+
"PT005", # deprecated
155+
"PT011",
156+
"PT012",
157+
"RUF001",
158+
"UP007",
159+
"UP027", # deprecated
160+
"UP038", # https://github.com/astral-sh/ruff/issues/7871
161+
]
142162

143163
[tool.ruff.format]
144164
quote-style = "preserve"

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,14 @@ def run(self):
333333
build_ext.run(self)
334334
except PlatformError as e:
335335
error(e)
336-
raise BuildFailed() from e
336+
raise BuildFailed from e
337337

338338
def build_extension(self, ext):
339339
try:
340340
build_ext.build_extension(self, ext)
341341
except ext_errors as e:
342342
error(e)
343-
raise BuildFailed() from e
343+
raise BuildFailed from e
344344

345345

346346
class Sclean(clean):

0 commit comments

Comments
 (0)