[New-bugs-announce] [issue16308] Undocumented (?) behaviour change in argparse from 3.2.3 to 3.3.0
telmich
report at bugs.python.org
Wed Oct 24 11:22:33 CEST 2012
New submission from telmich:
Using argparse with subparsers, the default behaviour if no subparser was selected, was to print help:
cdist% git describe
2.0.14-59-g5315c41
cdist% ./bin/cdist
usage: cdist [-h] [-d] [-v] [-V] {banner,config} ...
cdist: error: too few arguments
cdist% python3 -V
Python 3.2.3
With python 3.3.0, this changed and thus the so far uncalled code block is executed:
cdist% ./bin/cdist
Traceback (most recent call last):
File "./bin/cdist", line 237, in <module>
commandline()
File "./bin/cdist", line 104, in commandline
args.func(args)
AttributeError: 'Namespace' object has no attribute 'func'
cdist% git describe
2.0.14-59-g5315c41
cdist% python3 -V
Python 3.3.0
Question:
What is the correct way now to abort, if no subparser or
no option was given (i.e. restore the previous behaviour)?
I tried to fix this problem by using
parser['main'].set_defaults(func=commandline_main)
to setup a default handler for main, but this overwrites the func= parameter for all subparsers as well and thus renders this possibility useless (commits b7a8a84 and 840dbc5 in cdist).
The source code for cdist using the subparsers is available at http://git.schottelius.org/?p=cdist
----------
components: Library (Lib)
messages: 173659
nosy: telmich
priority: normal
severity: normal
status: open
title: Undocumented (?) behaviour change in argparse from 3.2.3 to 3.3.0
versions: Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16308>
_______________________________________
More information about the New-bugs-announce
mailing list