diff --git a/law/parameter.py b/law/parameter.py index ac51863f..57fd7a77 100644 --- a/law/parameter.py +++ b/law/parameter.py @@ -387,7 +387,7 @@ def _check_sort(self, value: tuple[T]) -> tuple[T]: return value key = self._sort if callable(self._sort) else None - return tuple(sorted(value, key=key)) # type: ignore[return-value] + return tuple(sorted(value, key=key)) # type: ignore[return-value, type-var] def _check_len(self, value: tuple[Any]) -> None: str_repr = lambda: ",".join(str(v) for v in value) diff --git a/law/target/file.py b/law/target/file.py index 2248f5a6..6c802315 100644 --- a/law/target/file.py +++ b/law/target/file.py @@ -208,6 +208,7 @@ def move( # type: ignore[override] ... @abstractmethod + @contextlib.contextmanager def open( self, path: str | pathlib.Path, @@ -216,7 +217,7 @@ def open( perm: int | None = None, dir_perm: int | None = None, **kwargs, - ) -> AbstractContextManager[IO]: + ) -> Iterator[IO]: ... @@ -441,7 +442,7 @@ def localize( dir_perm: int | None = None, tmp_dir: str | pathlib.Path | None = None, **kwargs, - ) -> Generator[FileSystemTarget, None, None]: + ) -> Iterator[FileSystemTarget]: ... @abstractmethod diff --git a/law/target/local.py b/law/target/local.py index 1c9ef7fb..24fa73ba 100644 --- a/law/target/local.py +++ b/law/target/local.py @@ -363,7 +363,7 @@ def move( # type: ignore[override] return dst - def open( + def open( # type: ignore[override] self, path: str | pathlib.Path, mode: str, diff --git a/law/target/mirrored.py b/law/target/mirrored.py index a0a70e52..bbadac74 100644 --- a/law/target/mirrored.py +++ b/law/target/mirrored.py @@ -22,7 +22,7 @@ RemoteFileSystem, RemoteTarget, RemoteFileTarget, RemoteDirectoryTarget, ) from law.util import patch_object -from law._types import Any, Type, Generator, AbstractContextManager, IO, Iterator +from law._types import Any, Type, Generator, Iterator, IO local_root_check_lock = threading.Lock() @@ -295,7 +295,7 @@ def move_from_local(self, *args, **kwargs) -> str: return ret @contextlib.contextmanager - def localize(self, mode: str = "r", **kwargs) -> Generator[FileSystemTarget, None, None]: + def localize(self, mode: str = "r", **kwargs) -> Iterator[FileSystemTarget]: with ( self.local_target.localize(mode=mode, **kwargs) if (mode == "r" or not self.local_read_only) and self._local_target_exists() @@ -336,12 +336,14 @@ class MirroredFileTarget(FileSystemFileTarget, MirroredTarget): def __init__(self, path: str | pathlib.Path, **kwargs) -> None: super().__init__(path, _is_file=True, **kwargs) - def open(self, mode: str, **kwargs) -> AbstractContextManager[IO]: - ret = ( + @contextlib.contextmanager + def open(self, mode: str, **kwargs) -> Iterator[IO]: + with ( self.local_target.open(mode, **kwargs) if (mode == "r" or not self.local_read_only) and self._local_target_exists() else self.remote_target.open(mode, **kwargs) - ) + ) as ret: + yield ret if mode == "w" and self.local_read_only and self.local_sync: self._wait_for_local(missing=False) return ret diff --git a/pyproject.toml b/pyproject.toml index 964dcf3b..2a3eb714 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -88,4 +88,4 @@ exclude = ["tests/*"] [tool.mypy] disable_error_code = ["no-redef", "valid-type", "method-assign"] -exclude = ["law/templates/*", "docs", "examples", "tests", "build"] +exclude = ["law/templates/*", "docs", "examples", "tests", "build", "setup.py"] diff --git a/requirements_dev.txt b/requirements_dev.txt index cb3ad191..477e1b5a 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -mypy~=1.11.1;python_version>="3.8" +mypy~=1.13.0;python_version>="3.8" flake8~=7.1.1;python_version>="3.8" flake8~=5.0.0;python_version<"3.8" flake8-commas~=2.1.0;python_version<"3.8"