Skip to content

Commit a0c7f4b

Browse files
cdce8pmypybot
authored and
mypybot
committed
Partially revert Clean up argparse hacks
1 parent 1a2b4a7 commit a0c7f4b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mypy/typeshed/stdlib/argparse.pyi

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from _typeshed import SupportsWrite, sentinel
33
from collections.abc import Callable, Generator, Iterable, Sequence
44
from re import Pattern
5-
from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload
5+
from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload
66
from typing_extensions import Self, TypeAlias, deprecated
77

88
__all__ = [
@@ -38,7 +38,9 @@ ONE_OR_MORE: Final = "+"
3838
OPTIONAL: Final = "?"
3939
PARSER: Final = "A..."
4040
REMAINDER: Final = "..."
41-
SUPPRESS: Final = "==SUPPRESS=="
41+
_SUPPRESS_T = NewType("_SUPPRESS_T", str)
42+
SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is
43+
# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy
4244
ZERO_OR_MORE: Final = "*"
4345
_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented
4446

@@ -81,7 +83,7 @@ class _ActionsContainer:
8183
# more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="],
8284
# but using this would make it hard to annotate callers that don't use a
8385
# literal argument and for subclasses to override this method.
84-
nargs: int | str | None = None,
86+
nargs: int | str | _SUPPRESS_T | None = None,
8587
const: Any = ...,
8688
default: Any = ...,
8789
type: _ActionType = ...,

0 commit comments

Comments
 (0)