Skip to content

Commit

Permalink
fixes typing of read_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Sep 16, 2024
1 parent c31c861 commit 447e7a1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
8 changes: 5 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import typing as ty
import pytest
from pathlib import Path

Expand All @@ -22,9 +23,10 @@ def cli_parse_only():
if os.getenv("_PYTEST_RAISE", "0") != "0":

@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(call):
raise call.excinfo.value
def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None:
if call.excinfo is not None:
raise call.excinfo.value

@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo):
def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None:
raise excinfo.value
8 changes: 5 additions & 3 deletions related-packages/fileformats-extras/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from pathlib import Path
import tempfile
import typing as ty
import pytest
from fileformats.medimage import DicomDir, Nifti

Expand All @@ -24,11 +25,12 @@
if os.getenv("_PYTEST_RAISE", "0") != "0":

@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(call):
raise call.excinfo.value
def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None:
if call.excinfo is not None:
raise call.excinfo.value

@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo):
def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None:
raise excinfo.value


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import numpy as np
import typing # noqa: F401
import numpy.typing
from fileformats.core import extra_implementation
from fileformats.medimage import DwiEncoding
from fileformats.medimage.diffusion import EncodingArrayType
from fileformats.medimage_mrtrix3 import BFile


@extra_implementation(DwiEncoding.read_array)
def bfile_read_array(bfile: BFile) -> np.ndarray:
return np.asarray(
def bfile_read_array(
bfile: BFile,
) -> EncodingArrayType:
return numpy.asarray(
[[float(x) for x in ln.split()] for ln in bfile.read_contents().splitlines()]
)
8 changes: 5 additions & 3 deletions related-packages/fileformats/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import logging
import typing as ty
from pathlib import Path
import tempfile
import pytest
Expand All @@ -23,11 +24,12 @@
if os.getenv("_PYTEST_RAISE", "0") != "0":

@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(call):
raise call.excinfo.value
def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None:
if call.excinfo is not None:
raise call.excinfo.value

@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo):
def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None:
raise excinfo.value


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ImageDataFile(File):

@extra_implementation(FileSet.read_metadata)
def mrtrix_read_metadata(
mif: BaseMrtrixImage, selected_keys: ty.Optional[ty.Collection[str]] = None
mif: BaseMrtrixImage, **kwargs: ty.Any
) -> ty.Mapping[str, ty.Any]:
metadata = {}
with open(mif.fspath, "rb") as f:
Expand Down Expand Up @@ -127,6 +127,4 @@ def mrtrix_read_metadata(
else:
metadata[key] = value
line = f.readline().decode("utf-8")
if selected_keys:
metadata = {k: v for k, v in metadata.items() if k in selected_keys}
return metadata

0 comments on commit 447e7a1

Please sign in to comment.