@@ -2,7 +2,7 @@ import sys
2
2
from _typeshed import SupportsWrite , sentinel
3
3
from collections .abc import Callable , Generator , Iterable , Sequence
4
4
from 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
6
6
from typing_extensions import Self , TypeAlias , deprecated
7
7
8
8
__all__ = [
@@ -33,25 +33,14 @@ _ActionT = TypeVar("_ActionT", bound=Action)
33
33
_ArgumentParserT = TypeVar ("_ArgumentParserT" , bound = ArgumentParser )
34
34
_N = TypeVar ("_N" )
35
35
_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
45
36
46
37
ONE_OR_MORE : Final = "+"
47
38
OPTIONAL : Final = "?"
48
39
PARSER : Final = "A..."
49
40
REMAINDER : 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=="
53
42
ZERO_OR_MORE : Final = "*"
54
- _UNRECOGNIZED_ARGS_ATTR : Final [ str ] # undocumented
43
+ _UNRECOGNIZED_ARGS_ATTR : Final = "_unrecognized_args" # undocumented
55
44
56
45
class ArgumentError (Exception ):
57
46
argument_name : str | None
@@ -86,8 +75,13 @@ class _ActionsContainer:
86
75
def add_argument (
87
76
self ,
88
77
* 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 ,
91
85
const : Any = ...,
92
86
default : Any = ...,
93
87
type : _ActionType = ...,
0 commit comments