Skip to content

Commit 1d93526

Browse files
committed
MNT: Remove workarounds used for Python 3.8 support
1 parent fcc2957 commit 1d93526

File tree

12 files changed

+20
-38
lines changed

12 files changed

+20
-38
lines changed

nibabel/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ def bench(label=None, verbose=1, extra_argv=None):
170170
code : ExitCode
171171
Returns the result of running the tests as a ``pytest.ExitCode`` enum
172172
"""
173-
try:
174-
from importlib.resources import as_file, files
175-
except ImportError:
176-
from importlib_resources import as_file, files
173+
from importlib.resources import as_file, files
177174

178175
args = []
179176
if extra_argv is not None:

nibabel/conftest.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
@pytest.fixture(scope='session', autouse=True)
1212
def legacy_printoptions():
13-
from packaging.version import Version
14-
15-
if Version(np.__version__) >= Version('1.22'):
16-
np.set_printoptions(legacy='1.21')
13+
np.set_printoptions(legacy='1.21')
1714

1815

1916
@pytest.fixture
@@ -24,7 +21,7 @@ def max_digits():
2421
orig_max_str_digits = sys.get_int_max_str_digits()
2522
yield sys.set_int_max_str_digits
2623
sys.set_int_max_str_digits(orig_max_str_digits)
27-
except AttributeError: # pragma: no cover
24+
except AttributeError: # PY310 # pragma: no cover
2825
# Nothing to do for versions of Python that lack these methods
2926
# They were added as DoS protection in Python 3.11 and backported to
3027
# some other versions.

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_init.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import pathlib
22
import unittest
3+
from importlib.resources import files
34
from unittest import mock
45

56
import pytest
67

7-
try:
8-
from importlib.resources import files
9-
except ImportError:
10-
from importlib_resources import files
11-
128
import nibabel as nib
139

1410

0 commit comments

Comments
 (0)