@@ -2,7 +2,7 @@ import sys
22from _typeshed import SupportsWrite , sentinel
33from collections .abc import Callable , Generator , Iterable , Sequence
44from re import Pattern
5- from typing import IO , Any , ClassVar , Final , Generic , NewType , NoReturn , Protocol , TypeVar , overload
5+ from typing import IO , Any , ClassVar , Final , Generic , NoReturn , Protocol , TypeVar , overload
66from typing_extensions import Self , TypeAlias , deprecated
77
88__all__ = [
@@ -33,25 +33,14 @@ _ActionT = TypeVar("_ActionT", bound=Action)
3333_ArgumentParserT = TypeVar ("_ArgumentParserT" , bound = ArgumentParser )
3434_N = TypeVar ("_N" )
3535_ActionType : TypeAlias = Callable [[str ], Any ] | FileType | str
36- # more precisely, Literal["store", "store_const", "store_true",
37- # "store_false", "append", "append_const", "count", "help", "version",
38- # "extend"], but using this would make it hard to annotate callers
39- # that don't use a literal argument
40- _ActionStr : TypeAlias = str
41- # more precisely, Literal["?", "*", "+", "...", "A...",
42- # "==SUPPRESS=="], but using this would make it hard to annotate
43- # callers that don't use a literal argument
44- _NArgsStr : TypeAlias = str
4536
4637ONE_OR_MORE : Final = "+"
4738OPTIONAL : Final = "?"
4839PARSER : Final = "A..."
4940REMAINDER : Final = "..."
50- _SUPPRESS_T = NewType ("_SUPPRESS_T" , str )
51- SUPPRESS : _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is
52- # the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy
41+ SUPPRESS : Final = "==SUPPRESS=="
5342ZERO_OR_MORE : Final = "*"
54- _UNRECOGNIZED_ARGS_ATTR : Final [ str ] # undocumented
43+ _UNRECOGNIZED_ARGS_ATTR : Final = "_unrecognized_args" # undocumented
5544
5645class ArgumentError (Exception ):
5746 argument_name : str | None
@@ -86,8 +75,13 @@ class _ActionsContainer:
8675 def add_argument (
8776 self ,
8877 * name_or_flags : str ,
89- action : _ActionStr | type [Action ] = ...,
90- nargs : int | _NArgsStr | _SUPPRESS_T | None = None ,
78+ # str covers predefined actions ("store_true", "count", etc.)
79+ # and user registered actions via the `register` method.
80+ action : str | type [Action ] = ...,
81+ # more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="],
82+ # but using this would make it hard to annotate callers that don't use a
83+ # literal argument and for subclasses to override this method.
84+ nargs : int | str | None = None ,
9185 const : Any = ...,
9286 default : Any = ...,
9387 type : _ActionType = ...,
0 commit comments