Skip to content

Commit

Permalink
chore: Enable mypy for pydantic_argparse
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpelsepp committed Nov 28, 2024
1 parent 37a269c commit e2c924e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default:

.PHONY: lint
lint:
uv run mypy src tests
uv run mypy --pretty src tests
uv run ruff check src tests
uv run ruff format --check src tests
find tests/bats \( -iname "*.bash" -or -iname "*.bats" -or -iname "*.sh" \) | xargs shellcheck
Expand Down
15 changes: 0 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,6 @@ strict = true
plugins = [
"pydantic.mypy"
]
exclude = [
"src/gallia/pydantic_argparse/.*"
]

# TODO: Make this compatible to --strict.
[[tool.mypy.overrides]]
module = ["gallia.pydantic_argparse"]
check_untyped_defs = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_decorators = true
disallow_any_unimported = true
warn_return_any = true
warn_unused_ignores = true
no_implicit_optional = true

[tool.ruff]
target-version = "py311"
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/pydantic_argparse/argparse/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
T = TypeVar("T")


class SubParsersAction(argparse._SubParsersAction):
class SubParsersAction(argparse._SubParsersAction): # type: ignore
"""Recursively Nesting Sub-Parsers Action for Typed Argument Parsing.
This custom action differs in functionality from the existing standard
Expand Down
8 changes: 5 additions & 3 deletions src/gallia/pydantic_argparse/argparse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(
self.extra_defaults = extra_defaults

# Add Arguments Groups
self._subcommands: argparse._SubParsersAction | None = None
self._subcommands: argparse._SubParsersAction[Any] | None = None

# Add Arguments from Model
self._submodels: dict[str, type[BaseModel]] = {}
Expand Down Expand Up @@ -136,7 +136,9 @@ def parse_typed_args(
# to report it to the user
self._validation_error(exc, nested_parser)

def _validation_error(self, error: ValidationError, parser: _NestedArgumentParser) -> Never:
def _validation_error(
self, error: ValidationError, parser: _NestedArgumentParser[Any]
) -> Never:
self.print_usage(sys.stderr)

model = parser.model
Expand Down Expand Up @@ -216,7 +218,7 @@ def error(self, message: str) -> NoReturn:
# Raise Error
# raise argparse.ArgumentError(None, msg)

def _commands(self) -> argparse._SubParsersAction:
def _commands(self) -> argparse._SubParsersAction: # type: ignore
"""Creates and Retrieves Subcommands Action for the ArgumentParser.
Returns:
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/pydantic_argparse/parsers/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def parse_field(
subparser: argparse._SubParsersAction,
subparser: argparse._SubParsersAction, # type: ignore
field: PydanticField,
extra_defaults: dict[type, dict[str, Any]] | None = None,
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/gallia/pydantic_argparse/utils/nesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from argparse import Namespace
from typing import Any, Generic, TypeAlias

from boltons.iterutils import get_path, remap
from boltons.iterutils import get_path, remap # type: ignore
from pydantic import BaseModel

from .namespaces import to_dict
Expand All @@ -30,7 +30,7 @@ def __init__(
self.schema: dict[str, Any] = self._get_nested_model_fields(self.model, namespace)
self.schema = self._remove_null_leaves(self.schema)

def _get_nested_model_fields(self, model: ModelT, namespace: Namespace) -> dict[str, Any]:
def _get_nested_model_fields(self, model: ModelT[Any], namespace: Namespace) -> dict[str, Any]:
def contains_subcommand(ns: Namespace, subcommand_path: tuple[str, ...]) -> bool:
for step in subcommand_path:
tmp = getattr(ns, step, None)
Expand Down
5 changes: 2 additions & 3 deletions src/gallia/pydantic_argparse/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
"""

from collections.abc import Iterable
from typing import Any

# Version-Guarded


def all_types(types: Iterable) -> bool:
def all_types(types: Iterable[Any]) -> bool:
"""Check if all inputs are `type`s and not instances.
Args:
Expand Down

0 comments on commit e2c924e

Please sign in to comment.