From f2048ff214c46d6f86b9b77e6a5252392a7646b3 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Wed, 11 Sep 2024 15:46:01 +0200 Subject: [PATCH] fix mypy warnings fix import --- .pre-commit-config.yaml | 2 +- pyproject.toml | 1 + src/npe2/_inspection/_fetch.py | 2 +- src/npe2/_inspection/_from_npe1.py | 2 +- src/npe2/manifest/contributions/_readers.py | 16 +++++++++++++--- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7812b6c0..92889788 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.3 + rev: v0.6.4 hooks: - id: ruff diff --git a/pyproject.toml b/pyproject.toml index 3177397e..e68dd92d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,6 +112,7 @@ select = [ [tool.ruff.per-file-ignores] "src/npe2/cli.py" = ["B008", "A00"] +"**/test_*.py" = ["RUF018"] [tool.ruff.pyupgrade] # Preserve types, even if a file imports `from __future__ import annotations`. diff --git a/src/npe2/_inspection/_fetch.py b/src/npe2/_inspection/_fetch.py index 53134274..cba09d27 100644 --- a/src/npe2/_inspection/_fetch.py +++ b/src/npe2/_inspection/_fetch.py @@ -59,7 +59,7 @@ def _manifest_from_npe2_dist( module: str = match.groupdict()["module"] attr: str = match.groupdict()["attr"] - mf_file = Path(dist.locate_file(Path(module.replace(".", os.sep)) / attr)) + mf_file = Path(dist.locate_file(Path(module.replace(".", os.sep)) / attr)) # type: ignore[arg-type] if not mf_file.exists(): raise ValueError( # pragma: no cover f"manifest {mf_file.name!r} does not exist in distribution " diff --git a/src/npe2/_inspection/_from_npe1.py b/src/npe2/_inspection/_from_npe1.py index 8a83a9d0..e644e760 100644 --- a/src/npe2/_inspection/_from_npe1.py +++ b/src/npe2/_inspection/_from_npe1.py @@ -516,7 +516,7 @@ def get_top_module_path(package_name, top_module: Optional[str] = None) -> Path: ) top_module = top_mods[0] - path = Path(dist.locate_file(top_module)) + path = Path(dist.locate_file(top_module)) # type: ignore[arg-type] if not path.is_dir() and dist.files: for f_path in dist.files: if "__editable__" in f_path.name: diff --git a/src/npe2/manifest/contributions/_readers.py b/src/npe2/manifest/contributions/_readers.py index 0135edd1..ba4fdfec 100644 --- a/src/npe2/manifest/contributions/_readers.py +++ b/src/npe2/manifest/contributions/_readers.py @@ -1,10 +1,13 @@ from functools import wraps -from typing import List, Optional +from typing import TYPE_CHECKING, List, Optional from npe2._pydantic_compat import Extra, Field from npe2.manifest.utils import Executable, v2_to_v1 from npe2.types import ReaderFunction +if TYPE_CHECKING: + from npe2._command_registry import CommandRegistry + class ReaderContribution(Executable[Optional[ReaderFunction]]): """Contribute a file reader. @@ -36,7 +39,12 @@ def __hash__(self): (self.command, tuple(self.filename_patterns), self.accepts_directories) ) - def exec(self, *, kwargs): + def exec( + self, + args: tuple = (), + kwargs: Optional[dict] = None, + _registry: Optional["CommandRegistry"] = None, + ): """ We are trying to simplify internal npe2 logic to always deal with a (list[str], bool) pair instead of Union[PathLike, Seq[Pathlike]]. We @@ -44,11 +52,13 @@ def exec(self, *, kwargs): on we could add a "if manifest.version == 2" or similar to not have this backward-compatibility logic for new plugins. """ + if kwargs is None: + kwargs = {} kwargs = kwargs.copy() stack = kwargs.pop("stack", None) assert stack is not None kwargs["path"] = v2_to_v1(kwargs["path"], stack) - callable_ = super().exec(kwargs=kwargs) + callable_ = super().exec(args=args, kwargs=kwargs, _registry=_registry) if callable_ is None: # pragma: no cover return None