From 95fe74d633f5a9dd7415b891920e679d5661c658 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Thu, 12 Sep 2024 14:41:27 +1000 Subject: [PATCH] fixed up mypy errors --- extras/fileformats/extras/medimage/diffusion.py | 5 +++-- extras/fileformats/extras/medimage/nifti.py | 6 +++--- fileformats/medimage/dicom.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/extras/fileformats/extras/medimage/diffusion.py b/extras/fileformats/extras/medimage/diffusion.py index 49bdb20..f8ec108 100644 --- a/extras/fileformats/extras/medimage/diffusion.py +++ b/extras/fileformats/extras/medimage/diffusion.py @@ -1,3 +1,4 @@ +import typing as ty import numpy as np import numpy.typing from fileformats.core import extra_implementation @@ -5,12 +6,12 @@ @extra_implementation(Bval.read_array) -def bval_read_array(bval: Bval) -> numpy.typing.NDArray[np.floating]: # noqa +def bval_read_array(bval: Bval) -> numpy.typing.NDArray[np.floating[ty.Any]]: # noqa return np.asarray([float(ln) for ln in bval.read_contents().split()]) @extra_implementation(DwiEncoding.read_array) -def bvec_read_array(bvec: Bvec) -> numpy.typing.NDArray[np.floating]: # noqa +def bvec_read_array(bvec: Bvec) -> numpy.typing.NDArray[np.floating[ty.Any]]: # noqa bvals = bvec.b_values_file.read_array() directions = np.asarray( [[float(x) for x in ln.split()] for ln in bvec.read_contents().splitlines()] diff --git a/extras/fileformats/extras/medimage/nifti.py b/extras/fileformats/extras/medimage/nifti.py index a0c87a6..aa7bdfc 100644 --- a/extras/fileformats/extras/medimage/nifti.py +++ b/extras/fileformats/extras/medimage/nifti.py @@ -28,15 +28,15 @@ def nifti_read_metadata( nifti: Nifti, selected_keys: ty.Optional[ty.Collection[str]] = None ) -> ty.Mapping[str, ty.Any]: - metadata = dict(nibabel.load(nifti.fspath).header) # type: ignore[attr-defined] + metadata = dict(nibabel.load(nifti.fspath).header) if selected_keys: metadata = {k: v for k, v in metadata.items() if k in selected_keys} return metadata @extra_implementation(MedicalImage.read_array) -def nifti_data_array(nifti: Nifti) -> numpy.typing.NDArray[np.floating]: # noqa - return nibabel.load(nifti.fspath).get_data() # type: ignore[attr-defined, no-any-return] +def nifti_data_array(nifti: Nifti) -> numpy.typing.NDArray[np.floating[ty.Any]]: # noqa + return nibabel.load(nifti.fspath).get_data() # type: ignore[no-any-return] @extra_implementation(MedicalImage.vox_sizes) diff --git a/fileformats/medimage/dicom.py b/fileformats/medimage/dicom.py index 232e7ce..48465cb 100644 --- a/fileformats/medimage/dicom.py +++ b/fileformats/medimage/dicom.py @@ -62,7 +62,7 @@ def from_paths( fspaths : ty.Iterable[Path] the fspaths pointing to the DICOM files common_ok : bool, optional - included to match the signature of the overriden method, but ignored as each + included to match the signature of the overridden method, but ignored as each dicom should belong to only one series. selected_keys : ty.Optional[ty.Collection[str]], optional metadata keys to load from the DICOM files, typically used for performance @@ -101,7 +101,7 @@ def dicom_collection_read_metadata( base_class: ty.Union[ty.Type[TypedSet], ty.Type[Directory]] = ( TypedSet if isinstance(collection, DicomSeries) else Directory ) - for dicom in base_class.contents.__get__(collection): # type: ignore[union-attr, arg-type] + for dicom in base_class.contents.__get__(collection): # type: ignore[arg-type] if selected_keys is not None: dicom = Dicom(dicom, metadata_keys=selected_keys) for key, val in dicom.metadata.items():