Message165441
The Namespace object contains a combined list of all of the arguments, from both the main parser and the subparser. I don't see any way to resolve identically name augments without breaking a lot of code that relies on the current behavior. I would instead propose that anyone needing to distinguish between identically named args in nested parsers use distinct names as the primary name of the argument, and the non-distictive name as an alias. For example:
parser.add_argument('--verbose(main)', '--verbose', ...)
Running the attached file produces the following output.
# using non-distinctive args
['--verbose', 'command'] => Namespace(command='command', verbose=True)
['command', '--verbose'] => Namespace(command='command', verbose=True)
['--verbose', 'command', '--verbose'] => Namespace(command='command', verbose=True)
# using distinctive args
['--verbose', 'command'] => Namespace(command='command', verbose(main)=True, verbose(subcommand)=False)
['command', '--verbose'] => Namespace(command='command', verbose(main)=False, verbose(subcommand)=True)
['--verbose', 'command', '--verbose'] => Namespace(command='command', verbose(main)=True, verbose(subcommand)=True) |
|
Date |
User |
Action |
Args |
2012-07-14 12:05:17 | samwyse | set | recipients:
+ samwyse, bethard, ezio.melotti, tshepang, Ingo.Fischer |
2012-07-14 12:05:16 | samwyse | set | messageid: <1342267516.88.0.973697180146.issue15327@psf.upfronthosting.co.za> |
2012-07-14 12:05:16 | samwyse | link | issue15327 messages |
2012-07-14 12:05:15 | samwyse | create | |
|