Skip to content

Commit

Permalink
chore: Remove TypeVar stuff and use native generic syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpelsepp committed Dec 19, 2024
1 parent d83ce5f commit 1847777
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
6 changes: 1 addition & 5 deletions src/gallia/pydantic_argparse/argparse/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
from collections.abc import Callable, Iterable, Sequence
from typing import (
Any,
TypeVar,
cast,
)

# Constants
T = TypeVar("T")


class SubParsersAction(argparse._SubParsersAction): # type: ignore
"""Recursively Nesting Sub-Parsers Action for Typed Argument Parsing.
Expand Down Expand Up @@ -141,7 +137,7 @@ class BooleanOptionalAction(argparse.Action): # pragma: no cover
<https://github.com/python/cpython/blob/v3.11.0/Lib/argparse.py#L878-L914>
"""

def __init__(
def __init__[T](
self,
option_strings: Sequence[str],
dest: str,
Expand Down
10 changes: 4 additions & 6 deletions src/gallia/pydantic_argparse/parsers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@

from argparse import Action, FileType
from collections.abc import Callable, Iterable
from typing import Any, Protocol, TypeVar

_T = TypeVar("_T")
from typing import Any, Protocol


class SupportsAddArgument(Protocol):
"""ArgumentParser protocol that captures the base parser and argument groups."""

def add_argument( # noqa: D102
def add_argument[T]( # noqa: D102
self,
*name_or_flags: str,
action: str | type[Action] = ...,
nargs: int | str = ...,
const: Any = ...,
default: Any = ...,
type: Callable[[str], _T] | FileType = ..., # noqa: A002
choices: Iterable[_T] | None = ...,
type: Callable[[str], T] | FileType = ..., # noqa: A002
choices: Iterable[T] | None = ...,
required: bool = ...,
help: str | None = ..., # noqa: A002
metavar: str | tuple[str, ...] | None = ...,
Expand Down
7 changes: 2 additions & 5 deletions src/gallia/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from collections.abc import Awaitable, Callable
from pathlib import Path
from types import ModuleType
from typing import TYPE_CHECKING, Any, TypeVar
from typing import TYPE_CHECKING, Any
from urllib.parse import urlparse

import aiofiles
Expand Down Expand Up @@ -193,10 +193,7 @@ def unravel_2d(listing: str) -> dict[int, list[int] | None]:
}


T = TypeVar("T")


async def catch_and_log_exception(
async def catch_and_log_exception[T](
func: Callable[..., Awaitable[T]],
*args: Any,
**kwargs: Any,
Expand Down

0 comments on commit 1847777

Please sign in to comment.