From 43af9968bd4bc1ded8a6afb02959d704dd948390 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Thu, 5 Sep 2024 06:42:39 +1000 Subject: [PATCH] changed signature of read_metadata to have collection instead of sequence --- extras/fileformats/extras/application/medical.py | 2 +- fileformats/core/fileset.py | 6 +++--- fileformats/core/mixin.py | 4 ++-- fileformats/core/tests/test_general.py | 2 +- fileformats/core/tests/test_metadata.py | 2 +- fileformats/core/tests/test_mixin.py | 2 +- fileformats/image/raster.py | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/extras/fileformats/extras/application/medical.py b/extras/fileformats/extras/application/medical.py index 5824f5f..9210038 100644 --- a/extras/fileformats/extras/application/medical.py +++ b/extras/fileformats/extras/application/medical.py @@ -9,7 +9,7 @@ @extra_implementation(FileSet.read_metadata) def dicom_read_metadata( - dicom: Dicom, selected_keys: ty.Optional[ty.Sequence[str]] = None + dicom: Dicom, selected_keys: ty.Optional[ty.Collection[str]] = None ) -> ty.Mapping[str, ty.Any]: dcm = pydicom.dcmread( dicom.fspath, diff --git a/fileformats/core/fileset.py b/fileformats/core/fileset.py index 7b27475..e685e9d 100644 --- a/fileformats/core/fileset.py +++ b/fileformats/core/fileset.py @@ -92,13 +92,13 @@ class FileSet(DataType): # Member attributes fspaths: ty.FrozenSet[Path] _explicit_metadata: ty.Optional[ty.Mapping[str, ty.Any]] - _metadata_keys: ty.Optional[ty.List[str]] + _metadata_keys: ty.Optional[ty.Collection[str]] def __init__( self, fspaths: FspathsInputType, metadata: ty.Optional[ty.Dict[str, ty.Any]] = None, - metadata_keys: ty.Optional[ty.List[str]] = None, + metadata_keys: ty.Optional[ty.Collection[str]] = None, ): self._explicit_metadata = metadata self._metadata_keys = metadata_keys @@ -263,7 +263,7 @@ def metadata(self) -> ty.Mapping[str, ty.Any]: @extra def read_metadata( - self, selected_keys: ty.Optional[ty.Sequence[str]] = None + self, selected_keys: ty.Optional[ty.Collection[str]] = None ) -> ty.Mapping[str, ty.Any]: """Reads any metadata associated with the fileset and returns it as a dict diff --git a/fileformats/core/mixin.py b/fileformats/core/mixin.py index 97c2c5b..01df4de 100644 --- a/fileformats/core/mixin.py +++ b/fileformats/core/mixin.py @@ -183,7 +183,7 @@ def header(self) -> "fileformats.core.FileSet": return self.header_type(self.select_by_ext(self.header_type)) # type: ignore[attr-defined] def read_metadata( - self, selected_keys: ty.Optional[ty.Sequence[str]] = None + self, selected_keys: ty.Optional[ty.Collection[str]] = None ) -> ty.Mapping[str, ty.Any]: header: ty.Dict[str, ty.Any] = self.header.load() # type: ignore[attr-defined] if selected_keys: @@ -221,7 +221,7 @@ def side_cars(self) -> ty.Tuple["fileformats.core.FileSet", ...]: return tuple(tp(self.select_by_ext(tp)) for tp in self.side_car_types) # type: ignore[attr-defined] def read_metadata( - self, selected_keys: ty.Optional[ty.Sequence[str]] = None + self, selected_keys: ty.Optional[ty.Collection[str]] = None ) -> ty.Mapping[str, ty.Any]: metadata: ty.Dict[str, ty.Any] = dict(self.primary_type.read_metadata(self, selected_keys=selected_keys)) # type: ignore[arg-type] for side_car in self.side_cars: diff --git a/fileformats/core/tests/test_general.py b/fileformats/core/tests/test_general.py index 8c41ab6..c1ff2b2 100644 --- a/fileformats/core/tests/test_general.py +++ b/fileformats/core/tests/test_general.py @@ -135,7 +135,7 @@ class ImageWithInlineHeader(File): header_separator = b"---END HEADER---" def read_metadata( - self, selected_keys: ty.Optional[ty.Sequence[str]] = None + self, selected_keys: ty.Optional[ty.Collection[str]] = None ) -> ty.Mapping[str, ty.Any]: hdr = self.contents.split(self.header_separator)[0].decode("utf-8") return {k: int(v) for k, v in (ln.split(":") for ln in hdr.splitlines())} diff --git a/fileformats/core/tests/test_metadata.py b/fileformats/core/tests/test_metadata.py index 90a1674..c801abc 100644 --- a/fileformats/core/tests/test_metadata.py +++ b/fileformats/core/tests/test_metadata.py @@ -11,7 +11,7 @@ class FileWithMetadata(File): @extra_implementation(FileSet.read_metadata) def aformat_read_metadata( - mf: FileWithMetadata, selected_keys: ty.Optional[ty.Sequence[str]] = None + mf: FileWithMetadata, selected_keys: ty.Optional[ty.Collection[str]] = None ) -> ty.Mapping[str, ty.Any]: with open(mf) as f: metadata = f.read() diff --git a/fileformats/core/tests/test_mixin.py b/fileformats/core/tests/test_mixin.py index 9472af2..b15f904 100644 --- a/fileformats/core/tests/test_mixin.py +++ b/fileformats/core/tests/test_mixin.py @@ -108,7 +108,7 @@ class ImageWithInlineHeader(File): header_separator = b"---END HEADER---" def read_metadata( - self, selected_keys: ty.Optional[ty.Sequence[str]] = None + self, selected_keys: ty.Optional[ty.Collection[str]] = None ) -> ty.Mapping[str, ty.Any]: hdr = self.contents.split(self.header_separator)[0].decode("utf-8") return dict(ln.split(":") for ln in hdr.splitlines()) diff --git a/fileformats/image/raster.py b/fileformats/image/raster.py index 46e998a..12ef1a5 100644 --- a/fileformats/image/raster.py +++ b/fileformats/image/raster.py @@ -13,7 +13,7 @@ DataArrayType: TypeAlias = ( ty.Any -) # "numpy.typing.NDArray[ty.Union[np.float_, np.int_]]" +) # "numpy.typing.NDArray[ty.Union[np.floating, np.integer]]" class RasterImage(Image):