homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients charlie.proctor, paul.j3, rrt
Date 2016年11月06日.18:15:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1478456113.24.0.337071569136.issue28609@psf.upfronthosting.co.za>
In-reply-to
Content
The current error message is the result of http://bugs.python.org/issue10424 and http://bugs.python.org/issue12776
Before the test was just:
 if positionals:
 self.error(_('too few arguments'))
The 2nd patch reworked the test to include the revised handling of defaults.
So the current error message just lists all the positionals which haven't been consumed. ARGUMENT wasn't consumed because COMMAND wasn't consumed. And technically that would be true even if ARGUMENT required arguments. Well, to be pickier, it as a 're' pattern like 'AA*' that failed. 
The proposed patch looks like it would work, but I haven't tested or looked at the unittests. But I wonder if such a patch is really needed. Are users really misled by the the current message?
===============
As for the usage, the current version allows you to give a tuple METAVAR, producing lines like:
 In [359]: a.metavar=('A','B')
 In [360]: parser.print_usage()
 usage: ipython3 [-h] [A [B ...]]
 In [361]: a.nargs='+'
 In [362]: parser.print_usage()
 usage: ipython3 [-h] A [B ...]
This display pattern is generated in HelpFormater._format_args, with these lines
 elif action.nargs == ZERO_OR_MORE:
 result = '[%s [%s ...]]' % get_metavar(2)
 elif action.nargs == ONE_OR_MORE:
 result = '%s [%s ...]' % get_metavar(2)
 elif action.nargs == REMAINDER:
 result = '...'
You could subclass HelpFormatter, and replace this method with one that performs as you want, (I just tried this)
 result = '[%s ...]' % get_metavar(1)
I wouldn't recommend this as default change, but if there was a enough demand it could added as another HelpFormatter subclass.
METAVAR lets me approximate your shorter version:
 In [4]: p.print_usage()
 usage: ipython3 [-h] [pos [pos ...]]
 In [5]: a.metavar=('pos','')
 In [6]: p.print_usage()
 usage: ipython3 [-h] [pos [...]]
 In [7]: a.nargs='+'
 In [8]: p.print_usage()
 usage: ipython3 [-h] pos [...]
It still has the [], but the name is gone.
History
Date User Action Args
2016年11月06日 18:15:13paul.j3setrecipients: + paul.j3, charlie.proctor, rrt
2016年11月06日 18:15:13paul.j3setmessageid: <1478456113.24.0.337071569136.issue28609@psf.upfronthosting.co.za>
2016年11月06日 18:15:13paul.j3linkissue28609 messages
2016年11月06日 18:15:12paul.j3create

AltStyle によって変換されたページ (->オリジナル) /