[New-bugs-announce] [issue27859] argparse - subparsers does not retain namespace

Nick Papior report at bugs.python.org
Thu Aug 25 11:02:10 EDT 2016


New submission from Nick Papior:

Using argparse does not retain the Namespace variable across sub-parsers.

This prohibits customization of Actions due to "upper" level arguments not being stored in the namespace passed to the sub-parsers.

Hence, one may not create different sub-parsers which depend on an upper level flag.

The reason is the subparser command:
    subnamespace, arg_strings = parser.parse_known_args(arg_strings, None)

Which by default passes `None` as the namespace argument.

A simple patch would be to copy the original namespace, which may then be altered. And subsequently restored, based on changes to that namespace.

----------
components: Library (Lib)
files: argparse_subspacenamespace.py
messages: 273654
nosy: Nick Papior
priority: normal
severity: normal
status: open
title: argparse - subparsers does not retain namespace
type: enhancement
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
Added file: https://bugs.python.org/file44222/argparse_subspacenamespace.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27859>
_______________________________________


More information about the New-bugs-announce mailing list