samwyse <samw...@gmail.com> added the comment: 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) ---------- nosy: +samwyse Added file: http://bugs.python.org/file26379/argparsetest.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15327> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com