Message190339
| Author |
paul.j3 |
| Recipients |
amcnabb, bethard, docs@python, guilherme-pg, paul.j3, r.david.murray, v+python |
| Date |
2013年05月30日.05:40:36 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1369892438.91.0.461861579324.issue14191@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
This is a refinement of the patch with Message188609.
In parse_known_intermixed_args, the temporary capture of formatted usage has been put in a try/finally structure.
Positionals are now 'deactivated' with
action.nargs = SUPPRESS
action.default = SUPPRESS
To use this, a 'nargs==SUPPRESS' case has been added to the relevant methods. In _get_args_pattern() it acts just like 'nargs=0'. In '_get_values()' it returns 'value=SUPPRESS'. The net effect is that, in take_action(), 'action' is not invoked, and that positional is not added to the namespace.
Previously I used nargs=0, which put a [] value in the namespace, which then had to be deleted.
I have not added anything about this SUPPRESS option to the documentation (PARSER isn't there either).
When the parser uses incompatible features (e.g. REMAINDER), this now raises a TypeError. The effect is similar to giving add_argument incompatible definitions. The 'fallback' that I used earlier can be implemented with a simple 'try/except TypeError'. Other parsing errors go through the usual ArgumentParser.error() method.
test_argparse.py has been changed to handle this TypeError. |
|