Skip to content

Commit

Permalink
fix mypy warnings
Browse files Browse the repository at this point in the history
fix import
  • Loading branch information
Czaki committed Sep 11, 2024
1 parent 979b459 commit f2048ff
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion src/npe2/_inspection/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion src/npe2/_inspection/_from_npe1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 13 additions & 3 deletions src/npe2/manifest/contributions/_readers.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -36,19 +39,26 @@ 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
thus wrap the Reader Contributions to still give them the old api. Later
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
Expand Down

0 comments on commit f2048ff

Please sign in to comment.