Skip to content

Commit

Permalink
fixing up typing for read_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Sep 16, 2024
1 parent c76f8b9 commit 64ba1d0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
12 changes: 3 additions & 9 deletions fileformats/core/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,8 @@ def nested_types(cls) -> ty.Tuple[ty.Type[Classifier], ...]:
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.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
def read_metadata(self, **kwargs: ty.Any) -> ty.Mapping[str, ty.Any]:
header: ty.Dict[str, ty.Any] = self.header.load()
if selected_keys:
header = {k: v for k, v in header.items() if k in selected_keys}
return header


Expand Down Expand Up @@ -221,10 +217,8 @@ class MyFileFormatWithSideCars(WithSideCars, MyFileFormat):
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.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]
def read_metadata(self, **kwargs: ty.Any) -> ty.Mapping[str, ty.Any]:
metadata: ty.Dict[str, ty.Any] = dict(self.primary_type.read_metadata(self, **kwargs)) # type: ignore[arg-type]
for side_car in self.side_cars:
try:
side_car_metadata: ty.Dict[str, ty.Any] = side_car.load()
Expand Down
4 changes: 1 addition & 3 deletions fileformats/core/tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ class ImageWithInlineHeader(File):

header_separator = b"---END HEADER---"

def read_metadata(
self, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
def read_metadata(self, **kwargs: ty.Any) -> 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())}

Expand Down
4 changes: 1 addition & 3 deletions fileformats/core/tests/test_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ class ImageWithInlineHeader(File):

header_separator = b"---END HEADER---"

def read_metadata(
self, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
def read_metadata(self, **kwargs: ty.Any) -> 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())

Expand Down

0 comments on commit 64ba1d0

Please sign in to comment.