Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop some literal types from argparse (add_argument) #7614

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions stdlib/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ _T = TypeVar("_T")
_ActionT = TypeVar("_ActionT", bound=Action)
_ArgumentParserT = TypeVar("_ArgumentParserT", bound=ArgumentParser)
_N = TypeVar("_N")
# more precisely, Literal["store", "store_const", "store_true",
# "store_false", "append", "append_const", "count", "help", "version",
# "extend"], but using this would make it hard to annotate callers
# that don't use a literal argument
_ActionStr = str
# more precisely, Literal["?", "*", "+", "...", "A...",
# "==SUPPRESS=="], but using this would make it hard to annotate
# callers that don't use a literal argument
_NArgsStr = str

ONE_OR_MORE: Literal["+"]
OPTIONAL: Literal["?"]
Expand Down Expand Up @@ -106,11 +115,8 @@ class _ActionsContainer:
def add_argument(
self,
*name_or_flags: str,
action: Literal[
"store", "store_const", "store_true", "store_false", "append", "append_const", "count", "help", "version", "extend"
]
| type[Action] = ...,
nargs: int | Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="] | _SUPPRESS_T = ...,
action: _ActionStr | type[Action] = ...,
nargs: int | _NArgsStr | _SUPPRESS_T = ...,
const: Any = ...,
default: Any = ...,
type: Callable[[str], _T] | FileType = ...,
Expand Down