fix: ArgParse's registry for the type keyword argument to add_argument (#12194)

This commit is contained in:
Kanishk Pachauri
2024-06-25 21:01:45 +05:30
committed by GitHub
parent 60443ca258
commit 309aebf9d7

View File

@@ -32,6 +32,7 @@ _T = TypeVar("_T")
_ActionT = TypeVar("_ActionT", bound=Action)
_ArgumentParserT = TypeVar("_ArgumentParserT", bound=ArgumentParser)
_N = TypeVar("_N")
_ActionType: TypeAlias = Callable[[str], Any] | FileType | str
# more precisely, Literal["store", "store_const", "store_true",
# "store_false", "append", "append_const", "count", "help", "version",
# "extend"], but using this would make it hard to annotate callers
@@ -89,7 +90,7 @@ class _ActionsContainer:
nargs: int | _NArgsStr | _SUPPRESS_T | None = None,
const: Any = ...,
default: Any = ...,
type: Callable[[str], _T] | FileType = ...,
type: _ActionType = ...,
choices: Iterable[_T] | None = ...,
required: bool = ...,
help: str | None = ...,
@@ -313,7 +314,7 @@ class Action(_AttributeHolder):
nargs: int | str | None
const: Any
default: Any
type: Callable[[str], Any] | FileType | None
type: _ActionType | None
choices: Iterable[Any] | None
required: bool
help: str | None