Skip to content

Commit 47d75de

Browse files
cdce8pmypybot
authored andcommitted
Partially revert Clean up argparse hacks
1 parent 24481f1 commit 47d75de

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 5 additions & 3 deletions
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__ = [
@@ -36,7 +36,9 @@ ONE_OR_MORE: Final = "+"
3636
OPTIONAL: Final = "?"
3737
PARSER: Final = "A..."
3838
REMAINDER: Final = "..."
39-
SUPPRESS: Final = "==SUPPRESS=="
39+
_SUPPRESS_T = NewType("_SUPPRESS_T", str)
40+
SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is
41+
# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy
4042
ZERO_OR_MORE: Final = "*"
4143
_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented
4244

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

0 commit comments

Comments
 (0)