Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce ruff/flake8-comprehensions rules (C4) #605

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numcodecs/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_config(self):
# override in sub-class if need special encoding of config values

# setup config object
config = dict(id=self.codec_id)
config = {'id': self.codec_id}

# by default, assume all non-private members are configuration
# parameters - override this in sub-class if not the case
Expand Down
12 changes: 6 additions & 6 deletions numcodecs/categorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def decode(self, buf, out=None):
return dec

def get_config(self):
config = dict(
id=self.codec_id,
labels=self.labels,
dtype=self.dtype.str,
astype=self.astype.str,
)
config = {
'id': self.codec_id,
'labels': self.labels,
'dtype': self.dtype.str,
'astype': self.astype.str,
}
return config

def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion numcodecs/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def decode(self, buf, out=None):

def get_config(self):
# override to handle encoding dtypes
return dict(id=self.codec_id, dtype=self.dtype.str, astype=self.astype.str)
return {'id': self.codec_id, 'dtype': self.dtype.str, 'astype': self.astype.str}

def __repr__(self):
r = f'{type(self).__name__}(dtype={self.dtype.str!r}'
Expand Down
14 changes: 7 additions & 7 deletions numcodecs/fixedscaleoffset.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ def decode(self, buf, out=None):

def get_config(self):
# override to handle encoding dtypes
return dict(
id=self.codec_id,
scale=self.scale,
offset=self.offset,
dtype=self.dtype.str,
astype=self.astype.str,
)
return {
'id': self.codec_id,
'scale': self.scale,
'offset': self.offset,
'dtype': self.dtype.str,
'astype': self.astype.str,
}

def __repr__(self):
r = f'{type(self).__name__}(scale={self.scale}, offset={self.offset}, dtype={self.dtype.str!r}'
Expand Down
22 changes: 11 additions & 11 deletions numcodecs/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ def __init__(
else:
separators = ', ', ': '
separators = tuple(separators)
self._encoder_config = dict(
skipkeys=skipkeys,
ensure_ascii=ensure_ascii,
check_circular=check_circular,
allow_nan=allow_nan,
indent=indent,
separators=separators,
sort_keys=sort_keys,
)
self._encoder_config = {
'skipkeys': skipkeys,
'ensure_ascii': ensure_ascii,
'check_circular': check_circular,
'allow_nan': allow_nan,
'indent': indent,
'separators': separators,
'sort_keys': sort_keys,
}
self._encoder = _json.JSONEncoder(**self._encoder_config)
self._decoder_config = dict(strict=strict)
self._decoder_config = {'strict': strict}
self._decoder = _json.JSONDecoder(**self._decoder_config)

def encode(self, buf):
Expand All @@ -89,7 +89,7 @@ def decode(self, buf, out=None):
return dec

def get_config(self):
config = dict(id=self.codec_id, encoding=self._text_encoding)
config = {'id': self.codec_id, 'encoding': self._text_encoding}
config.update(self._encoder_config)
config.update(self._decoder_config)
return config
Expand Down
12 changes: 6 additions & 6 deletions numcodecs/msgpacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ def decode(self, buf, out=None):
return dec

def get_config(self):
return dict(
id=self.codec_id,
raw=self.raw,
use_single_float=self.use_single_float,
use_bin_type=self.use_bin_type,
)
return {
'id': self.codec_id,
'raw': self.raw,
'use_single_float': self.use_single_float,
'use_bin_type': self.use_bin_type,
}

def __repr__(self):
return f'MsgPack(raw={self.raw!r}, use_bin_type={self.use_bin_type!r}, use_single_float={self.use_single_float!r})'
2 changes: 1 addition & 1 deletion numcodecs/pickles.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def decode(self, buf, out=None):
return dec

def get_config(self):
return dict(id=self.codec_id, protocol=self.protocol)
return {'id': self.codec_id, 'protocol': self.protocol}

def __repr__(self):
return f'Pickle(protocol={self.protocol})'
12 changes: 6 additions & 6 deletions numcodecs/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def decode(self, buf, out=None):

def get_config(self):
# override to handle encoding dtypes
return dict(
id=self.codec_id,
digits=self.digits,
dtype=self.dtype.str,
astype=self.astype.str,
)
return {
'id': self.codec_id,
'digits': self.digits,
'dtype': self.dtype.str,
'astype': self.astype.str,
}

def __repr__(self):
r = f'{type(self).__name__}(digits={self.digits}, dtype={self.dtype.str!r}'
Expand Down
4 changes: 2 additions & 2 deletions numcodecs/tests/test_blosc.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ def test_config_blocksize():
# explicitly stated

# blocksize not stated
config = dict(cname='lz4', clevel=1, shuffle=Blosc.SHUFFLE)
config = {"cname": 'lz4', "clevel": 1, "shuffle": Blosc.SHUFFLE}
codec = Blosc.from_config(config)
assert codec.blocksize == 0

# blocksize stated
config = dict(cname='lz4', clevel=1, shuffle=Blosc.SHUFFLE, blocksize=2**8)
config = {"cname": 'lz4', "clevel": 1, "shuffle": Blosc.SHUFFLE, "blocksize": 2**8}
codec = Blosc.from_config(config)
assert codec.blocksize == 2**8

Expand Down
2 changes: 1 addition & 1 deletion numcodecs/tests/test_lzma.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
LZMA(preset=1),
LZMA(preset=5),
LZMA(preset=9),
LZMA(format=_lzma.FORMAT_RAW, filters=[dict(id=_lzma.FILTER_LZMA2, preset=1)]),
LZMA(format=_lzma.FORMAT_RAW, filters=[{"id": _lzma.FILTER_LZMA2, "preset": 1}]),
]


Expand Down
4 changes: 2 additions & 2 deletions numcodecs/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_all_classes_registered():

see #346 for more info
"""
missing = set(
missing = {
obj.codec_id
for _, submod in inspect.getmembers(numcodecs, inspect.ismodule)
for _, obj in inspect.getmembers(submod)
Expand All @@ -36,7 +36,7 @@ def test_all_classes_registered():
and obj.codec_id not in numcodecs.registry.codec_registry
and obj.codec_id is not None # remove `None`
)
)
}

if missing:
raise Exception(f"these codecs are missing: {missing}") # pragma: no cover
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ line-length = 100
[tool.ruff.lint]
extend-select = [
"B",
"C4",
"FLY",
"FURB",
"G",
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@


def info(*msg):
kwargs = dict(file=sys.stdout)
kwargs = {'file': sys.stdout}
print('[numcodecs]', *msg, **kwargs)


def error(*msg):
kwargs = dict(file=sys.stderr)
kwargs = {'file': sys.stderr}
print('[numcodecs]', *msg, **kwargs)


Expand Down Expand Up @@ -368,7 +368,7 @@ def run_setup(with_extensions):
+ jenkins_extension()
)

cmdclass = dict(build_ext=ve_build_ext, clean=Sclean)
cmdclass = {'build_ext': ve_build_ext, 'clean': Sclean}
else:
ext_modules = []
cmdclass = {}
Expand Down
Loading