Skip to content

Commit

Permalink
Merge pull request #1353 from DimitriPapadopoulos/C4
Browse files Browse the repository at this point in the history
STY: Enforce ruff/flake8-comprehensions rules (C4)
  • Loading branch information
effigies authored Sep 22, 2024
2 parents 9438297 + a28ce64 commit 4c216b1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion nibabel/brikhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def parse_AFNI_header(fobj):
return parse_AFNI_header(src)
# unpack variables in HEAD file
head = fobj.read().split('\n\n')
return {key: value for key, value in map(_unpack_var, head)}
return dict(map(_unpack_var, head))


class AFNIArrayProxy(ArrayProxy):
Expand Down
2 changes: 1 addition & 1 deletion nibabel/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def able_int_type(values):
>>> able_int_type([-1, 1]) == np.int8
True
"""
if any([v % 1 for v in values]):
if any(v % 1 for v in values):
return None
mn = min(values)
mx = max(values)
Expand Down
6 changes: 3 additions & 3 deletions nibabel/cifti2/tests/test_cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_cifti2_metadata():
assert len(md) == 1
assert list(iter(md)) == ['a']
assert md['a'] == 'aval'
assert md.data == dict([('a', 'aval')])
assert md.data == {'a': 'aval'}

with pytest.warns(FutureWarning):
md = ci.Cifti2MetaData(metadata={'a': 'aval'})
Expand All @@ -57,7 +57,7 @@ def test_cifti2_metadata():
md['a'] = 'aval'
assert md['a'] == 'aval'
assert len(md) == 1
assert md.data == dict([('a', 'aval')])
assert md.data == {'a': 'aval'}

del md['a']
assert len(md) == 0
Expand Down Expand Up @@ -392,7 +392,7 @@ def test_matrix():
m[0] = mim_1
assert list(m.mapped_indices) == [1]
m.insert(0, mim_0)
assert list(sorted(m.mapped_indices)) == [0, 1]
assert sorted(m.mapped_indices) == [0, 1]
assert h.number_of_mapped_indices == 2
assert h.get_index_map(0) == mim_0
assert h.get_index_map(1) == mim_1
Expand Down
4 changes: 1 addition & 3 deletions nibabel/nicom/dicomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,7 @@ def __init__(self, dcm_data, frame_filters=None):
frame_slc_pos = [np.inner(ipp, self.slice_normal) for ipp in frame_ipps]
rnd_slc_pos = np.round(frame_slc_pos, 4)
uniq_slc_pos = np.unique(rnd_slc_pos)
pos_ord_map = {
val: order for val, order in zip(uniq_slc_pos, np.argsort(uniq_slc_pos))
}
pos_ord_map = dict(zip(uniq_slc_pos, np.argsort(uniq_slc_pos)))
self._frame_slc_ord = [pos_ord_map[pos] for pos in rnd_slc_pos]
if len(self._frame_slc_ord) > 1:
self._slice_spacing = (
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ exclude = ["doc", "nibabel/externals", "tools", "version.py", "versioneer.py"]
[tool.ruff.lint]
select = [
"B",
"C4",
"F",
"I",
"PLE",
Expand All @@ -135,6 +136,9 @@ ignore = [
"B023", # TODO: enable
"B028",
"B904",
"C401",
"C408",
"C416",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
Expand Down

0 comments on commit 4c216b1

Please sign in to comment.