[issue16308] Undocumented (?) behaviour change in argparse from 3.2.3 to 3.3.0

telmich report at bugs.python.org
Wed Oct 24 16:12:14 CEST 2012


telmich added the comment:

I've copy & pasted the example from the documentation and added the following lines to it (attached full file)

args = parser.parse_args('')
args.func(args)

Following the style / way show in the documentation, I'd expect this block to work (3.2.2 behaviour). I do however understand from a logical point that this does not work:

* no subparsers are required
* no argument is required

=> args.func is never setup

One could check for this situation using getattr:

    try:
        a = getattr(args, "func")
    except AttributeError:
        parser['main'].print_help()
        sys.exit(0)

Though this look quite manual compared to the usual way of using argparse.

----------
Added file: http://bugs.python.org/file27695/subparse2.py

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


More information about the Python-bugs-list mailing list