Skip to content

Commit 1cccb0b

Browse files
authored
Typeshed cherry-pick: Drop some literal types from argparse (add_argument) (#7614) (#12576)
From python/typeshed#7614.
1 parent 74df7fb commit 1cccb0b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ _T = TypeVar("_T")
6262
_ActionT = TypeVar("_ActionT", bound=Action)
6363
_ArgumentParserT = TypeVar("_ArgumentParserT", bound=ArgumentParser)
6464
_N = TypeVar("_N")
65+
# more precisely, Literal["store", "store_const", "store_true",
66+
# "store_false", "append", "append_const", "count", "help", "version",
67+
# "extend"], but using this would make it hard to annotate callers
68+
# that don't use a literal argument
69+
_ActionStr = str
70+
# more precisely, Literal["?", "*", "+", "...", "A...",
71+
# "==SUPPRESS=="], but using this would make it hard to annotate
72+
# callers that don't use a literal argument
73+
_NArgsStr = str
6574

6675
ONE_OR_MORE: Literal["+"]
6776
OPTIONAL: Literal["?"]
@@ -106,11 +115,8 @@ class _ActionsContainer:
106115
def add_argument(
107116
self,
108117
*name_or_flags: str,
109-
action: Literal[
110-
"store", "store_const", "store_true", "store_false", "append", "append_const", "count", "help", "version", "extend"
111-
]
112-
| type[Action] = ...,
113-
nargs: int | Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="] | _SUPPRESS_T = ...,
118+
action: _ActionStr | type[Action] = ...,
119+
nargs: int | _NArgsStr | _SUPPRESS_T = ...,
114120
const: Any = ...,
115121
default: Any = ...,
116122
type: Callable[[str], _T] | FileType = ...,

0 commit comments

Comments
 (0)