Skip to content

Commit bfebbc7

Browse files
MNT: Use tuples instead of list where possible
Suggested by refurb: [FURB109]: Replace `in [x, y, z]` with `in (x, y, z)`
1 parent 1ee4983 commit bfebbc7

File tree

10 files changed

+20
-20
lines changed

10 files changed

+20
-20
lines changed

nibabel/cifti2/cifti2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,13 +968,13 @@ def vertex_indices(self, value):
968968
def _to_xml_element(self):
969969
brain_model = xml.Element('BrainModel')
970970

971-
for key in [
971+
for key in (
972972
'IndexOffset',
973973
'IndexCount',
974974
'ModelType',
975975
'BrainStructure',
976976
'SurfaceNumberOfVertices',
977-
]:
977+
):
978978
attr = _underscore(key)
979979
value = getattr(self, attr)
980980
if value is not None:
@@ -1157,14 +1157,14 @@ def _to_xml_element(self):
11571157
mat_ind_map = xml.Element('MatrixIndicesMap')
11581158
dims_as_strings = [str(dim) for dim in self.applies_to_matrix_dimension]
11591159
mat_ind_map.attrib['AppliesToMatrixDimension'] = ','.join(dims_as_strings)
1160-
for key in [
1160+
for key in (
11611161
'IndicesMapToDataType',
11621162
'NumberOfSeriesPoints',
11631163
'SeriesExponent',
11641164
'SeriesStart',
11651165
'SeriesStep',
11661166
'SeriesUnit',
1167-
]:
1167+
):
11681168
attr = _underscore(key)
11691169
value = getattr(self, attr)
11701170
if value is not None:

nibabel/cifti2/parse_cifti2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ def StartElementHandler(self, name, attrs):
203203
applies_to_matrix_dimension=dimensions,
204204
indices_map_to_data_type=attrs['IndicesMapToDataType'],
205205
)
206-
for key, dtype in [
206+
for key, dtype in (
207207
('NumberOfSeriesPoints', int),
208208
('SeriesExponent', int),
209209
('SeriesStart', float),
210210
('SeriesStep', float),
211211
('SeriesUnit', str),
212-
]:
212+
):
213213
if key in attrs:
214214
setattr(mim, _underscore(key), dtype(attrs[key]))
215215
matrix = self.struct_state[-1]
@@ -366,13 +366,13 @@ def StartElementHandler(self, name, attrs):
366366
'BrainModel element can only be a child of a MatrixIndicesMap '
367367
'with CIFTI_INDEX_TYPE_BRAIN_MODELS type'
368368
)
369-
for key, dtype in [
369+
for key, dtype in (
370370
('IndexOffset', int),
371371
('IndexCount', int),
372372
('ModelType', str),
373373
('BrainStructure', str),
374374
('SurfaceNumberOfVertices', int),
375-
]:
375+
):
376376
if key in attrs:
377377
setattr(model, _underscore(key), dtype(attrs[key]))
378378
if model.brain_structure not in CIFTI_BRAIN_STRUCTURES:

nibabel/cmdline/ls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def proc_file(f, opts):
110110
if (
111111
hasattr(h, 'has_data_slope')
112112
and (h.has_data_slope or h.has_data_intercept)
113-
and not h.get_slope_inter() in [(1.0, 0.0), (None, None)]
113+
and not h.get_slope_inter() in ((1.0, 0.0), (None, None))
114114
):
115115
row += ['@l*%.3g+%.3g' % h.get_slope_inter()]
116116
else:

nibabel/cmdline/parrec2nii.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def main():
414414

415415
verbose.switch = opts.verbose
416416

417-
if opts.origin not in ['scanner', 'fov']:
417+
if opts.origin not in ('scanner', 'fov'):
418418
error(f"Unrecognized value for --origin: '{opts.origin}'.", 1)
419419
if opts.dwell_time and opts.field_strength is None:
420420
error('Need --field-strength for dwell time calculation', 1)

nibabel/cmdline/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ def table2string(table, out=None):
7373
if item.startswith('@'):
7474
align = item[1]
7575
item = item[2:]
76-
if align not in ['l', 'r', 'c', 'w']:
76+
if align not in ('l', 'r', 'c', 'w'):
7777
raise ValueError(f'Unknown alignment {align}. Known are l,r,c')
7878
else:
7979
align = 'c'
8080

8181
nspacesl = max(ceil((col_width[j] - len(item)) / 2.0), 0)
8282
nspacesr = max(col_width[j] - nspacesl - len(item), 0)
8383

84-
if align in ['w', 'c']:
84+
if align in ('w', 'c'):
8585
pass
8686
elif align == 'l':
8787
nspacesl, nspacesr = 0, nspacesl + nspacesr

nibabel/freesurfer/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _read_volume_info(fobj):
6363
return volume_info
6464

6565
volume_info['head'] = head
66-
for key in ['valid', 'filename', 'volume', 'voxelsize', 'xras', 'yras', 'zras', 'cras']:
66+
for key in ('valid', 'filename', 'volume', 'voxelsize', 'xras', 'yras', 'zras', 'cras'):
6767
pair = fobj.readline().decode('utf-8').split('=')
6868
if pair[0].strip() != key or len(pair) != 2:
6969
raise OSError('Error parsing volume info.')

nibabel/gifti/gifti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _to_xml_element(self):
228228
label = xml.SubElement(labeltable, 'Label')
229229
label.attrib['Key'] = str(ele.key)
230230
label.text = ele.label
231-
for attr in ['Red', 'Green', 'Blue', 'Alpha']:
231+
for attr in ('Red', 'Green', 'Blue', 'Alpha'):
232232
if getattr(ele, attr.lower(), None) is not None:
233233
label.attrib[attr] = str(getattr(ele, attr.lower()))
234234
return labeltable

nibabel/gifti/parse_gifti_fast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def EndElementHandler(self, name):
333333
self.fsm_state.pop()
334334
self.coordsys = None
335335

336-
elif name in ['DataSpace', 'TransformedSpace', 'MatrixData', 'Name', 'Value', 'Data']:
336+
elif name in ('DataSpace', 'TransformedSpace', 'MatrixData', 'Name', 'Value', 'Data'):
337337
self.write_to = None
338338

339339
elif name == 'Label':

nibabel/streamlines/array_sequence.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def fn_binary_op(self, value):
7272
fn.__name__ = op
7373
fn.__doc__ = getattr(np.ndarray, op).__doc__
7474

75-
for op in [
75+
for op in (
7676
'__add__',
7777
'__sub__',
7878
'__mul__',
@@ -85,14 +85,14 @@ def fn_binary_op(self, value):
8585
'__or__',
8686
'__and__',
8787
'__xor__',
88-
]:
88+
):
8989
_wrap(cls, op=op, inplace=False)
9090
_wrap(cls, op=f"__i{op.strip('_')}__", inplace=True)
9191

92-
for op in ['__eq__', '__ne__', '__lt__', '__le__', '__gt__', '__ge__']:
92+
for op in ('__eq__', '__ne__', '__lt__', '__le__', '__gt__', '__ge__'):
9393
_wrap(cls, op)
9494

95-
for op in ['__neg__', '__abs__', '__invert__']:
95+
for op in ('__neg__', '__abs__', '__invert__'):
9696
_wrap(cls, op, unary=True)
9797

9898
return cls

nibabel/viewers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def _on_keypress(self, event):
501501
"""Handle mpl keypress events"""
502502
if event.key is not None and 'escape' in event.key:
503503
self.close()
504-
elif event.key in ['=', '+']:
504+
elif event.key in ('=', '+'):
505505
# increment volume index
506506
new_idx = min(self._data_idx[3] + 1, self.n_volumes)
507507
self._set_volume_index(new_idx, update_slices=True)

0 commit comments

Comments
 (0)