Skip to content

Commit e7c3481

Browse files
committed
Drop some literal types from argparse (add_argument)
These were introduced in python#7329 and they cause false positives in code that used to be accepted before. There was a false positive in https://github.com/pycqa/pylint (encountered in python/mypy#12321) and I also saw false positives in an internal codebase. I suggest not using literal types here, since they can be kind of awkward to annotate in callers that don't pass a literal string. Rrequiring callers to write annotations like `Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="]` is not very user friendly.
1 parent 79c654e commit e7c3481

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

stdlib/argparse.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,8 @@ class _ActionsContainer:
106106
def add_argument(
107107
self,
108108
*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 = ...,
109+
action: str | type[Action] = ...,
110+
nargs: int | str | _SUPPRESS_T = ...,
114111
const: Any = ...,
115112
default: Any = ...,
116113
type: Callable[[str], _T] | FileType = ...,

0 commit comments

Comments
 (0)