Skip to content

Commit d4eede3

Browse files
STY: Apply ruff rule RUF012
RUF012 Mutable class attributes should be annotated with `typing.ClassVar` Co-authored-by: Chris Markiewicz <[email protected]>
1 parent 3b1c7b3 commit d4eede3

File tree

7 files changed

+12
-15
lines changed

7 files changed

+12
-15
lines changed

doc/tools/apigen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ApiDocWriter:
3232
to Sphinx-parsable reST format"""
3333

3434
# only separating first two levels
35-
rst_section_levels = ['*', '=', '-', '~', '^']
35+
rst_section_levels = ('*', '=', '-', '~', '^')
3636

3737
def __init__(
3838
self,

nibabel/analyze.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484

8585
from __future__ import annotations
8686

87+
import typing as ty
88+
8789
import numpy as np
8890

8991
from .arrayproxy import ArrayProxy
@@ -92,6 +94,7 @@
9294
from .fileholders import copy_file_map
9395
from .spatialimages import HeaderDataError, HeaderTypeError, SpatialHeader, SpatialImage
9496
from .volumeutils import (
97+
Recoder,
9598
apply_read_scaling,
9699
array_from_file,
97100
make_dt_codes,
@@ -185,7 +188,7 @@ class AnalyzeHeader(LabeledWrapStruct, SpatialHeader):
185188
template_dtype = header_dtype
186189
_data_type_codes = data_type_codes
187190
# fields with recoders for their values
188-
_field_recoders = {'datatype': data_type_codes}
191+
_field_recoders: ty.ClassVar[dict[str, Recoder]] = {'datatype': data_type_codes}
189192
# default x flip
190193
default_x_flip = True
191194

nibabel/cifti2/cifti2.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,14 +1045,6 @@ class Cifti2MatrixIndicesMap(xml.XmlSerializable, MutableSequence):
10451045
If it is a series, units
10461046
"""
10471047

1048-
_valid_type_mappings_ = {
1049-
Cifti2BrainModel: ('CIFTI_INDEX_TYPE_BRAIN_MODELS',),
1050-
Cifti2Parcel: ('CIFTI_INDEX_TYPE_PARCELS',),
1051-
Cifti2NamedMap: ('CIFTI_INDEX_TYPE_LABELS',),
1052-
Cifti2Volume: ('CIFTI_INDEX_TYPE_SCALARS', 'CIFTI_INDEX_TYPE_SERIES'),
1053-
Cifti2Surface: ('CIFTI_INDEX_TYPE_SCALARS', 'CIFTI_INDEX_TYPE_SERIES'),
1054-
}
1055-
10561048
def __init__(
10571049
self,
10581050
applies_to_matrix_dimension,

nibabel/nifti1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ class Nifti1Header(SpmAnalyzeHeader):
811811
_data_type_codes = data_type_codes
812812

813813
# fields with recoders for their values
814-
_field_recoders = {
814+
_field_recoders: ty.ClassVar[dict[str, Recoder]] = {
815815
'datatype': data_type_codes,
816816
'qform_code': xform_codes,
817817
'sform_code': xform_codes,

nibabel/openers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Opener:
131131
gz_def = (_gzip_open, ('mode', 'compresslevel', 'mtime', 'keep_open'))
132132
bz2_def = (BZ2File, ('mode', 'buffering', 'compresslevel'))
133133
zstd_def = (_zstd_open, ('mode', 'level_or_option', 'zstd_dict'))
134-
compress_ext_map: dict[str | None, OpenerDef] = {
134+
compress_ext_map: ty.ClassVar[dict[str | None, OpenerDef]] = {
135135
'.gz': gz_def,
136136
'.bz2': bz2_def,
137137
'.zst': zstd_def,
@@ -141,7 +141,7 @@ class Opener:
141141
default_compresslevel = 1
142142
#: default option for zst files
143143
default_zst_compresslevel = 3
144-
default_level_or_option = {
144+
default_level_or_option: ty.ClassVar[dict[str, int | None]] = {
145145
'rb': None,
146146
'r': None,
147147
'wb': default_zst_compresslevel,

nibabel/wrapstruct.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112

113113
from __future__ import annotations
114114

115+
from typing import ClassVar
116+
115117
import numpy as np
116118

117119
from . import imageglobals as imageglobals
@@ -485,7 +487,7 @@ def _get_checks(klass):
485487
class LabeledWrapStruct(WrapStruct):
486488
"""A WrapStruct with some fields having value labels for printing etc"""
487489

488-
_field_recoders: dict[str, Recoder] = {} # for recoding values for str
490+
_field_recoders: ClassVar[dict[str, Recoder]] = {} # for recoding values for str
489491

490492
def get_value_label(self, fieldname):
491493
"""Returns label for coded field

nibabel/xmlutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class XmlParser:
4949
CharacterDataHandler
5050
"""
5151

52-
HANDLER_NAMES = ['StartElementHandler', 'EndElementHandler', 'CharacterDataHandler']
52+
HANDLER_NAMES = ('StartElementHandler', 'EndElementHandler', 'CharacterDataHandler')
5353

5454
def __init__(self, encoding='utf-8', buffer_size=35000000, verbose=0):
5555
"""

0 commit comments

Comments
 (0)