Skip to content

Commit 2886549

Browse files
committed
MNT: Remove workarounds used for Python 3.8 support
1 parent a3b406a commit 2886549

File tree

9 files changed

+16
-24
lines changed

9 files changed

+16
-24
lines changed

nibabel/filebasedimages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
if ty.TYPE_CHECKING:
2424
from .filename_parser import ExtensionSpec, FileSpec
2525

26-
FileSniff = ty.Tuple[bytes, str]
26+
FileSniff = tuple[bytes, str]
2727

2828
ImgT = ty.TypeVar('ImgT', bound='FileBasedImage')
2929
HdrT = ty.TypeVar('HdrT', bound='FileBasedHeader')

nibabel/nicom/ascconv.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ def assign2atoms(assign_ast, default_class=int):
9090
target = target.value
9191
prev_target_type = OrderedDict
9292
elif isinstance(target, ast.Subscript):
93-
if isinstance(target.slice, ast.Constant): # PY39
94-
index = target.slice.value
95-
else: # PY38
96-
index = target.slice.value.n
93+
index = target.slice.value
9794
atoms.append(Atom(target, prev_target_type, index))
9895
target = target.value
9996
prev_target_type = list

nibabel/nifti1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def _mangle(self, dataset: DicomDataset) -> bytes:
671671
(38, 'eval', NiftiExtension),
672672
(40, 'matlab', NiftiExtension),
673673
(42, 'quantiphyse', NiftiExtension),
674-
(44, 'mrs', NiftiExtension[ty.Dict[str, ty.Any]]),
674+
(44, 'mrs', NiftiExtension[dict[str, ty.Any]]),
675675
),
676676
fields=('code', 'label', 'handler'),
677677
)

nibabel/spatialimages.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
from __future__ import annotations
134134

135135
import typing as ty
136+
from functools import cache
136137
from typing import Literal
137138

138139
import numpy as np
@@ -145,11 +146,6 @@
145146
from .viewers import OrthoSlicer3D
146147
from .volumeutils import shape_zoom_affine
147148

148-
try:
149-
from functools import cache
150-
except ImportError: # PY38
151-
from functools import lru_cache as cache
152-
153149
if ty.TYPE_CHECKING:
154150
import io
155151
from collections.abc import Sequence

nibabel/testing/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import unittest
1818
import warnings
1919
from contextlib import nullcontext
20+
from importlib.resources import as_file, files
2021
from itertools import zip_longest
2122

2223
import numpy as np
@@ -29,11 +30,6 @@
2930
if ty.TYPE_CHECKING:
3031
from importlib.resources.abc import Traversable
3132

32-
try:
33-
from importlib.resources import as_file, files
34-
except ImportError: # PY38
35-
from importlib_resources import as_file, files
36-
3733

3834
def get_test_data(
3935
subdir: ty.Literal['gifti', 'nicom', 'externals'] | None = None,

nibabel/testing/np_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Look for changes in numpy behavior over versions"""
22

3-
from functools import lru_cache
3+
from functools import cache
44

55
import numpy as np
66

77

8-
@lru_cache(maxsize=None)
8+
@cache
99
def memmap_after_ufunc() -> bool:
1010
"""Return True if ufuncs on memmap arrays always return memmap arrays
1111

nibabel/tests/test_arrayproxy.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,11 @@ def test_keep_file_open_true_false_invalid():
482482

483483
for test in tests:
484484
filetype, kfo, have_igzip, exp_persist, exp_kfo = test
485-
with InTemporaryDirectory(), mock.patch(
486-
'nibabel.openers.ImageOpener', CountingImageOpener
487-
), patch_indexed_gzip(have_igzip):
485+
with (
486+
InTemporaryDirectory(),
487+
mock.patch('nibabel.openers.ImageOpener', CountingImageOpener),
488+
patch_indexed_gzip(have_igzip),
489+
):
488490
fname = f'testdata.{filetype}'
489491
# create the test data file
490492
if filetype == 'gz':

nibabel/tests/test_openers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ def patch_indexed_gzip(state):
121121
values = (True, MockIndexedGzipFile)
122122
else:
123123
values = (False, GzipFile)
124-
with mock.patch('nibabel.openers.HAVE_INDEXED_GZIP', values[0]), mock.patch(
125-
'nibabel.openers.IndexedGzipFile', values[1], create=True
124+
with (
125+
mock.patch('nibabel.openers.HAVE_INDEXED_GZIP', values[0]),
126+
mock.patch('nibabel.openers.IndexedGzipFile', values[1], create=True),
126127
):
127128
yield
128129

nibabel/volumeutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def value_set(self, name: str | None = None) -> OrderedSet:
235235
endian_codes = Recoder(_endian_codes)
236236

237237

238-
class DtypeMapper(ty.Dict[ty.Hashable, ty.Hashable]):
238+
class DtypeMapper(dict[ty.Hashable, ty.Hashable]):
239239
"""Specialized mapper for numpy dtypes
240240
241241
We pass this mapper into the Recoder class to deal with numpy dtype

0 commit comments

Comments
 (0)