Skip to content

Commit 4c216b1

Browse files
authored
Merge pull request #1353 from DimitriPapadopoulos/C4
STY: Enforce ruff/flake8-comprehensions rules (C4)
2 parents 9438297 + a28ce64 commit 4c216b1

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

nibabel/brikhead.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def parse_AFNI_header(fobj):
198198
return parse_AFNI_header(src)
199199
# unpack variables in HEAD file
200200
head = fobj.read().split('\n\n')
201-
return {key: value for key, value in map(_unpack_var, head)}
201+
return dict(map(_unpack_var, head))
202202

203203

204204
class AFNIArrayProxy(ArrayProxy):

nibabel/casting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def able_int_type(values):
764764
>>> able_int_type([-1, 1]) == np.int8
765765
True
766766
"""
767-
if any([v % 1 for v in values]):
767+
if any(v % 1 for v in values):
768768
return None
769769
mn = min(values)
770770
mx = max(values)

nibabel/cifti2/tests/test_cifti2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_cifti2_metadata():
3737
assert len(md) == 1
3838
assert list(iter(md)) == ['a']
3939
assert md['a'] == 'aval'
40-
assert md.data == dict([('a', 'aval')])
40+
assert md.data == {'a': 'aval'}
4141

4242
with pytest.warns(FutureWarning):
4343
md = ci.Cifti2MetaData(metadata={'a': 'aval'})
@@ -57,7 +57,7 @@ def test_cifti2_metadata():
5757
md['a'] = 'aval'
5858
assert md['a'] == 'aval'
5959
assert len(md) == 1
60-
assert md.data == dict([('a', 'aval')])
60+
assert md.data == {'a': 'aval'}
6161

6262
del md['a']
6363
assert len(md) == 0
@@ -392,7 +392,7 @@ def test_matrix():
392392
m[0] = mim_1
393393
assert list(m.mapped_indices) == [1]
394394
m.insert(0, mim_0)
395-
assert list(sorted(m.mapped_indices)) == [0, 1]
395+
assert sorted(m.mapped_indices) == [0, 1]
396396
assert h.number_of_mapped_indices == 2
397397
assert h.get_index_map(0) == mim_0
398398
assert h.get_index_map(1) == mim_1

nibabel/nicom/dicomwrappers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,7 @@ def __init__(self, dcm_data, frame_filters=None):
685685
frame_slc_pos = [np.inner(ipp, self.slice_normal) for ipp in frame_ipps]
686686
rnd_slc_pos = np.round(frame_slc_pos, 4)
687687
uniq_slc_pos = np.unique(rnd_slc_pos)
688-
pos_ord_map = {
689-
val: order for val, order in zip(uniq_slc_pos, np.argsort(uniq_slc_pos))
690-
}
688+
pos_ord_map = dict(zip(uniq_slc_pos, np.argsort(uniq_slc_pos)))
691689
self._frame_slc_ord = [pos_ord_map[pos] for pos in rnd_slc_pos]
692690
if len(self._frame_slc_ord) > 1:
693691
self._slice_spacing = (

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ exclude = ["doc", "nibabel/externals", "tools", "version.py", "versioneer.py"]
117117
[tool.ruff.lint]
118118
select = [
119119
"B",
120+
"C4",
120121
"F",
121122
"I",
122123
"PLE",
@@ -135,6 +136,9 @@ ignore = [
135136
"B023", # TODO: enable
136137
"B028",
137138
"B904",
139+
"C401",
140+
"C408",
141+
"C416",
138142
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
139143
"W191",
140144
"E111",

0 commit comments

Comments
 (0)