diff --git a/nibabel/cifti2/cifti2.py b/nibabel/cifti2/cifti2.py index 34aed5a9e..452bceb7e 100644 --- a/nibabel/cifti2/cifti2.py +++ b/nibabel/cifti2/cifti2.py @@ -968,13 +968,13 @@ def vertex_indices(self, value): def _to_xml_element(self): brain_model = xml.Element('BrainModel') - for key in [ + for key in ( 'IndexOffset', 'IndexCount', 'ModelType', 'BrainStructure', 'SurfaceNumberOfVertices', - ]: + ): attr = _underscore(key) value = getattr(self, attr) if value is not None: @@ -1157,14 +1157,14 @@ def _to_xml_element(self): mat_ind_map = xml.Element('MatrixIndicesMap') dims_as_strings = [str(dim) for dim in self.applies_to_matrix_dimension] mat_ind_map.attrib['AppliesToMatrixDimension'] = ','.join(dims_as_strings) - for key in [ + for key in ( 'IndicesMapToDataType', 'NumberOfSeriesPoints', 'SeriesExponent', 'SeriesStart', 'SeriesStep', 'SeriesUnit', - ]: + ): attr = _underscore(key) value = getattr(self, attr) if value is not None: diff --git a/nibabel/cifti2/parse_cifti2.py b/nibabel/cifti2/parse_cifti2.py index c7bfb953f..48c2e0653 100644 --- a/nibabel/cifti2/parse_cifti2.py +++ b/nibabel/cifti2/parse_cifti2.py @@ -203,13 +203,13 @@ def StartElementHandler(self, name, attrs): applies_to_matrix_dimension=dimensions, indices_map_to_data_type=attrs['IndicesMapToDataType'], ) - for key, dtype in [ + for key, dtype in ( ('NumberOfSeriesPoints', int), ('SeriesExponent', int), ('SeriesStart', float), ('SeriesStep', float), ('SeriesUnit', str), - ]: + ): if key in attrs: setattr(mim, _underscore(key), dtype(attrs[key])) matrix = self.struct_state[-1] @@ -366,13 +366,13 @@ def StartElementHandler(self, name, attrs): 'BrainModel element can only be a child of a MatrixIndicesMap ' 'with CIFTI_INDEX_TYPE_BRAIN_MODELS type' ) - for key, dtype in [ + for key, dtype in ( ('IndexOffset', int), ('IndexCount', int), ('ModelType', str), ('BrainStructure', str), ('SurfaceNumberOfVertices', int), - ]: + ): if key in attrs: setattr(model, _underscore(key), dtype(attrs[key])) if model.brain_structure not in CIFTI_BRAIN_STRUCTURES: diff --git a/nibabel/cmdline/ls.py b/nibabel/cmdline/ls.py index 4f504910a..ff41afbd0 100755 --- a/nibabel/cmdline/ls.py +++ b/nibabel/cmdline/ls.py @@ -110,7 +110,7 @@ def proc_file(f, opts): if ( hasattr(h, 'has_data_slope') and (h.has_data_slope or h.has_data_intercept) - and not h.get_slope_inter() in [(1.0, 0.0), (None, None)] + and not h.get_slope_inter() in ((1.0, 0.0), (None, None)) ): row += ['@l*%.3g+%.3g' % h.get_slope_inter()] else: diff --git a/nibabel/cmdline/parrec2nii.py b/nibabel/cmdline/parrec2nii.py index c04a6e019..934062639 100644 --- a/nibabel/cmdline/parrec2nii.py +++ b/nibabel/cmdline/parrec2nii.py @@ -414,7 +414,7 @@ def main(): verbose.switch = opts.verbose - if opts.origin not in ['scanner', 'fov']: + if opts.origin not in ('scanner', 'fov'): error(f"Unrecognized value for --origin: '{opts.origin}'.", 1) if opts.dwell_time and opts.field_strength is None: error('Need --field-strength for dwell time calculation', 1) diff --git a/nibabel/cmdline/utils.py b/nibabel/cmdline/utils.py index 8e9d45251..214923570 100644 --- a/nibabel/cmdline/utils.py +++ b/nibabel/cmdline/utils.py @@ -73,7 +73,7 @@ def table2string(table, out=None): if item.startswith('@'): align = item[1] item = item[2:] - if align not in ['l', 'r', 'c', 'w']: + if align not in ('l', 'r', 'c', 'w'): raise ValueError(f'Unknown alignment {align}. Known are l,r,c') else: align = 'c' @@ -81,7 +81,7 @@ def table2string(table, out=None): nspacesl = max(ceil((col_width[j] - len(item)) / 2.0), 0) nspacesr = max(col_width[j] - nspacesl - len(item), 0) - if align in ['w', 'c']: + if align in ('w', 'c'): pass elif align == 'l': nspacesl, nspacesr = 0, nspacesl + nspacesr diff --git a/nibabel/freesurfer/io.py b/nibabel/freesurfer/io.py index 95d4eed0f..b4d6ef2a3 100644 --- a/nibabel/freesurfer/io.py +++ b/nibabel/freesurfer/io.py @@ -63,7 +63,7 @@ def _read_volume_info(fobj): return volume_info volume_info['head'] = head - for key in ['valid', 'filename', 'volume', 'voxelsize', 'xras', 'yras', 'zras', 'cras']: + for key in ('valid', 'filename', 'volume', 'voxelsize', 'xras', 'yras', 'zras', 'cras'): pair = fobj.readline().decode('utf-8').split('=') if pair[0].strip() != key or len(pair) != 2: raise OSError('Error parsing volume info.') diff --git a/nibabel/gifti/gifti.py b/nibabel/gifti/gifti.py index 16261ee67..76bad4677 100644 --- a/nibabel/gifti/gifti.py +++ b/nibabel/gifti/gifti.py @@ -228,7 +228,7 @@ def _to_xml_element(self): label = xml.SubElement(labeltable, 'Label') label.attrib['Key'] = str(ele.key) label.text = ele.label - for attr in ['Red', 'Green', 'Blue', 'Alpha']: + for attr in ('Red', 'Green', 'Blue', 'Alpha'): if getattr(ele, attr.lower(), None) is not None: label.attrib[attr] = str(getattr(ele, attr.lower())) return labeltable diff --git a/nibabel/gifti/parse_gifti_fast.py b/nibabel/gifti/parse_gifti_fast.py index e4a9be4bd..7d8eacb82 100644 --- a/nibabel/gifti/parse_gifti_fast.py +++ b/nibabel/gifti/parse_gifti_fast.py @@ -333,7 +333,7 @@ def EndElementHandler(self, name): self.fsm_state.pop() self.coordsys = None - elif name in ['DataSpace', 'TransformedSpace', 'MatrixData', 'Name', 'Value', 'Data']: + elif name in ('DataSpace', 'TransformedSpace', 'MatrixData', 'Name', 'Value', 'Data'): self.write_to = None elif name == 'Label': diff --git a/nibabel/nifti1.py b/nibabel/nifti1.py index 890bc2e22..e0bdd2020 100644 --- a/nibabel/nifti1.py +++ b/nibabel/nifti1.py @@ -1636,10 +1636,11 @@ def set_slice_times(self, slice_times): labels = so_recoder.value_set('label') labels.remove('unknown') - matching_labels = [] - for label in labels: - if np.all(st_order == self._slice_time_order(label, n_timed)): - matching_labels.append(label) + matching_labels = [ + label + for label in labels + if np.all(st_order == self._slice_time_order(label, n_timed)) + ] if not matching_labels: raise HeaderDataError(f'slice ordering of {st_order} fits with no known scheme') diff --git a/nibabel/streamlines/array_sequence.py b/nibabel/streamlines/array_sequence.py index faa5d2390..dd9b3c57d 100644 --- a/nibabel/streamlines/array_sequence.py +++ b/nibabel/streamlines/array_sequence.py @@ -72,7 +72,7 @@ def fn_binary_op(self, value): fn.__name__ = op fn.__doc__ = getattr(np.ndarray, op).__doc__ - for op in [ + for op in ( '__add__', '__sub__', '__mul__', @@ -85,14 +85,14 @@ def fn_binary_op(self, value): '__or__', '__and__', '__xor__', - ]: + ): _wrap(cls, op=op, inplace=False) _wrap(cls, op=f"__i{op.strip('_')}__", inplace=True) - for op in ['__eq__', '__ne__', '__lt__', '__le__', '__gt__', '__ge__']: + for op in ('__eq__', '__ne__', '__lt__', '__le__', '__gt__', '__ge__'): _wrap(cls, op) - for op in ['__neg__', '__abs__', '__invert__']: + for op in ('__neg__', '__abs__', '__invert__'): _wrap(cls, op, unary=True) return cls diff --git a/nibabel/viewers.py b/nibabel/viewers.py index f2b32a1fd..60ebd3a25 100644 --- a/nibabel/viewers.py +++ b/nibabel/viewers.py @@ -501,7 +501,7 @@ def _on_keypress(self, event): """Handle mpl keypress events""" if event.key is not None and 'escape' in event.key: self.close() - elif event.key in ['=', '+']: + elif event.key in ('=', '+'): # increment volume index new_idx = min(self._data_idx[3] + 1, self.n_volumes) self._set_volume_index(new_idx, update_slices=True)