[issue9351] argparse set_defaults on subcommands should override top level set_defaults

Rémi Rampin report at bugs.python.org
Wed Jun 3 20:35:56 CEST 2015


Rémi Rampin added the comment:

To me this is much more than a compatibility problem. The way it worked before made a lot of sense, and just felt like the "correct" solution to accept a flag in multiple places.

Having a --verbose flag is something everybody should consider (Python has a decent builtin logging module), and anybody providing it would definitely want to accept it before and after subcommands (or at least, for every subcommand).

The only way right now is to not only create different arguments with add_argument(), for each parser, but you also need to provide different destination names (and then do something shitty like verbosity = args.verb_main+args.verb_subcommand). This bug makes argparse completely unusable for any real-life application that uses subparsers (in addition to breaking existing programs). And it breaks silently too, simply amazing!

Of course there is very little point in fixing this now. Since this affects multiple released versions of Python, I have to use a work-around anyway (until I can move from argparse to something that won't decide to break someday for the hell of it).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9351>
_______________________________________


More information about the Python-bugs-list mailing list