Skip to content

Commit 4563c5a

Browse files
EvanKrallJelleZijlstra
authored andcommitted
ArgumentParser's add_argument returns the Action that was created. (#1881)
* ArgumentParser's add_argument returns the Action that was created. * Make add_argument's dest parameter Optional. _ArgumentGroup's add_argument should also return the Action.
1 parent 0170e6d commit 4563c5a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

stdlib/2and3/argparse.pyi

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class ArgumentParser:
7575
required: bool = ...,
7676
help: _Text = ...,
7777
metavar: Union[_Text, Tuple[_Text, ...]] = ...,
78-
dest: _Text = ...,
79-
version: _Text = ...) -> None: ... # weirdly documented
78+
dest: Optional[_Text] = ...,
79+
version: _Text = ...) -> Action: ...
8080
def parse_args(self, args: Optional[Sequence[_Text]] = ...,
8181
namespace: Optional[Namespace] = ...) -> Namespace: ...
8282
def add_subparsers(self, title: _Text = ...,
@@ -120,11 +120,12 @@ class Action:
120120
nargs: Optional[Union[int, _Text]]
121121
const: Any
122122
default: Any
123-
type: Optional[Union[Callable[[str], Any], FileType]]
123+
type: Union[Callable[[str], Any], FileType, None]
124124
choices: Optional[Iterable[Any]]
125125
required: bool
126126
help: Optional[_Text]
127-
metavar: Optional[Union[_Text, Tuple[_Text, ...]]]
127+
metavar: Union[_Text, Tuple[_Text, ...]]
128+
128129
def __init__(self,
129130
option_strings: Sequence[_Text],
130131
dest: _Text = ...,
@@ -171,8 +172,8 @@ class _ArgumentGroup:
171172
required: bool = ...,
172173
help: _Text = ...,
173174
metavar: Union[_Text, Tuple[_Text, ...]] = ...,
174-
dest: _Text = ...,
175-
version: _Text = ...) -> None: ...
175+
dest: Optional[_Text] = ...,
176+
version: _Text = ...) -> Action: ...
176177
def add_mutually_exclusive_group(self, required: bool = ...) -> _MutuallyExclusiveGroup: ...
177178

178179
class _MutuallyExclusiveGroup(_ArgumentGroup): ...

0 commit comments

Comments
 (0)