Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove TypeVar stuff and use native generic syntax #652

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading