From 1ec84885bc40ea459252fb74e45945f25bd804f1 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Tue, 26 Dec 2023 00:12:12 +0100 Subject: [PATCH] MNT: Apply Repo-Review suggestions --- nibabel/_compression.py | 4 ++-- nibabel/benchmarks/bench_arrayproxy_slicing.py | 2 +- nibabel/cmdline/dicomfs.py | 2 +- nibabel/externals/conftest.py | 2 +- nibabel/minc2.py | 2 +- nibabel/parrec.py | 2 +- nibabel/pydicom_compat.py | 2 +- nibabel/spm99analyze.py | 2 +- nibabel/tmpdirs.py | 2 +- nibabel/xmlutils.py | 2 +- pyproject.toml | 4 +++- 11 files changed, 14 insertions(+), 12 deletions(-) diff --git a/nibabel/_compression.py b/nibabel/_compression.py index bf13895c80..75a5e3bbf4 100644 --- a/nibabel/_compression.py +++ b/nibabel/_compression.py @@ -17,7 +17,7 @@ from .optpkg import optional_package if ty.TYPE_CHECKING: # pragma: no cover - import indexed_gzip # type: ignore + import indexed_gzip # type: ignore[import-not-found] import pyzstd HAVE_INDEXED_GZIP = True @@ -40,7 +40,7 @@ if HAVE_INDEXED_GZIP: COMPRESSED_FILE_LIKES += (indexed_gzip.IndexedGzipFile,) COMPRESSION_ERRORS += (indexed_gzip.ZranError,) - from indexed_gzip import IndexedGzipFile # type: ignore + from indexed_gzip import IndexedGzipFile # type: ignore[import-not-found] else: IndexedGzipFile = gzip.GzipFile diff --git a/nibabel/benchmarks/bench_arrayproxy_slicing.py b/nibabel/benchmarks/bench_arrayproxy_slicing.py index 958923d7ea..dc9acfdedd 100644 --- a/nibabel/benchmarks/bench_arrayproxy_slicing.py +++ b/nibabel/benchmarks/bench_arrayproxy_slicing.py @@ -26,7 +26,7 @@ # if memory_profiler is installed, we get memory usage results try: - from memory_profiler import memory_usage # type: ignore + from memory_profiler import memory_usage # type: ignore[import-not-found] except ImportError: memory_usage = None diff --git a/nibabel/cmdline/dicomfs.py b/nibabel/cmdline/dicomfs.py index 85d7d8dcad..dec4011c51 100644 --- a/nibabel/cmdline/dicomfs.py +++ b/nibabel/cmdline/dicomfs.py @@ -25,7 +25,7 @@ class dummy_fuse: try: - import fuse # type: ignore + import fuse # type: ignore[import-not-found] uid = os.getuid() gid = os.getgid() diff --git a/nibabel/externals/conftest.py b/nibabel/externals/conftest.py index 33f88eb323..472f2f0296 100644 --- a/nibabel/externals/conftest.py +++ b/nibabel/externals/conftest.py @@ -6,7 +6,7 @@ import os from contextlib import contextmanager - @contextmanager # type: ignore + @contextmanager # type: ignore[no-redef] def _chdir(path): cwd = os.getcwd() os.chdir(path) diff --git a/nibabel/minc2.py b/nibabel/minc2.py index 3096ef9499..94e1be76e2 100644 --- a/nibabel/minc2.py +++ b/nibabel/minc2.py @@ -163,7 +163,7 @@ class Minc2Image(Minc1Image): def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None): # Import of h5py might take awhile for MPI-enabled builds # So we are importing it here "on demand" - import h5py # type: ignore + import h5py # type: ignore[import-not-found] holder = file_map['image'] if holder.filename is None: diff --git a/nibabel/parrec.py b/nibabel/parrec.py index ec3fdea711..3a8a6030de 100644 --- a/nibabel/parrec.py +++ b/nibabel/parrec.py @@ -1338,7 +1338,7 @@ def from_filename( strict_sort=strict_sort, ) - load = from_filename # type: ignore + load = from_filename # type: ignore[assignment] load = PARRECImage.from_filename diff --git a/nibabel/pydicom_compat.py b/nibabel/pydicom_compat.py index fae24e691c..d61c880117 100644 --- a/nibabel/pydicom_compat.py +++ b/nibabel/pydicom_compat.py @@ -42,7 +42,7 @@ if have_dicom: # Values not imported by default - import pydicom.values # type: ignore + import pydicom.values # type: ignore[import-not-found] from pydicom.dicomio import dcmread as read_file # noqa:F401 from pydicom.sequence import Sequence # noqa:F401 diff --git a/nibabel/spm99analyze.py b/nibabel/spm99analyze.py index 974f8609cf..c859d702f4 100644 --- a/nibabel/spm99analyze.py +++ b/nibabel/spm99analyze.py @@ -275,7 +275,7 @@ def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None): contents = matf.read() if len(contents) == 0: return ret - import scipy.io as sio # type: ignore + import scipy.io as sio # type: ignore[import-not-found] mats = sio.loadmat(BytesIO(contents)) if 'mat' in mats: # this overrides a 'M', and includes any flip diff --git a/nibabel/tmpdirs.py b/nibabel/tmpdirs.py index 7fe47e6510..49d69d2bf2 100644 --- a/nibabel/tmpdirs.py +++ b/nibabel/tmpdirs.py @@ -15,7 +15,7 @@ from contextlib import chdir as _chdir except ImportError: # PY310 - @contextmanager # type: ignore + @contextmanager # type: ignore[no-redef] def _chdir(path): cwd = os.getcwd() os.chdir(path) diff --git a/nibabel/xmlutils.py b/nibabel/xmlutils.py index 4a5fb28979..d3a7a08309 100644 --- a/nibabel/xmlutils.py +++ b/nibabel/xmlutils.py @@ -32,7 +32,7 @@ def to_xml(self, enc='utf-8', **kwargs) -> bytes: Additional keyword arguments to :func:`xml.etree.ElementTree.tostring`. """ ele = self._to_xml_element() - return b'' if ele is None else tostring(ele, enc, **kwargs) + return tostring(ele, enc, **kwargs) class XmlBasedHeader(FileBasedHeader, XmlSerializable): diff --git a/pyproject.toml b/pyproject.toml index 9fec3975cc..14095b8f22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,7 +111,7 @@ __version_tuple__ = version_tuple = {version_tuple!r} [tool.blue] line_length = 99 -target-version = ["py37"] +target-version = ["py38"] force-exclude = """ ( _version.py @@ -130,6 +130,8 @@ python_version = "3.11" exclude = [ "/tests", ] +warn_unreachable = true +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] [tool.codespell] skip = "*/data/*,./nibabel-data"