Skip to content

Commit 71058d2

Browse files
committed
argparse subnamespace: Make 'subnamespace' explicit in signature of _SubParsersAction.add_parser
Instead of it being mixed into kwargs, we keep 'subnamespace' separate like 'deprecated'. This makes it clearer that 'subnamespace' isn't intended as a parameter to be passed to the subparser constructor.
1 parent 6ed63b3 commit 71058d2

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

Lib/argparse.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,13 +1317,11 @@ def __init__(self,
13171317
help=help,
13181318
metavar=metavar)
13191319

1320-
def add_parser(self, name, *, deprecated=False, **kwargs):
1320+
def add_parser(self, name, *, deprecated=False, subnamespace=None, **kwargs):
13211321
# set prog from the existing prefix
13221322
if kwargs.get('prog') is None:
13231323
kwargs['prog'] = '%s %s' % (self._prog_prefix, name)
13241324

1325-
subnamespace_name = kwargs.pop('subnamespace', None)
1326-
13271325
# set color
13281326
if kwargs.get('color') is None:
13291327
kwargs['color'] = self._color
@@ -1352,8 +1350,8 @@ def add_parser(self, name, *, deprecated=False, **kwargs):
13521350

13531351
# add the subnamespace attribute to the parser if specified
13541352
# for nested namespaces
1355-
if subnamespace_name is not None:
1356-
setattr(parser, 'subnamespace', subnamespace_name)
1353+
if subnamespace is not None:
1354+
setattr(parser, 'subnamespace', subnamespace)
13571355

13581356
# make parser available under aliases also
13591357
for alias in aliases:

0 commit comments

Comments
 (0)