Glenn Linderman v+pyt...@g.nevcal.com added the comment:
See also issue 15258 which points out issues with the converse case.
Further testing and development also discovered that in certain error cases,
the help message produced by t18-equivalent code was incorrect.
t18a.py is an
R. David Murray rdmur...@bitdance.com added the comment:
To answer Glenn's procedural question: no this is not a bug whose fix can be
backported. API changes are not allowed in maintenance releases. Doc
improvements can be backported, though, so I'm leaving versios alone
(alternatively
Glenn Linderman v+pyt...@g.nevcal.com added the comment:
Sad. That means all the documentation of workarounds needs to be written, even
figured out in the first place. Steven's code, while being a nice
implementation when proper arguments are provided, produces inappropriate
errors, because
Glenn Linderman v+pyt...@g.nevcal.com added the comment:
Of course, if a real solution can only be shipped in 3.3, it may want to use
a different API than parse_args to avoid the parameter, parse_intermixed_args,
perhaps. But my t18.py uses the name parse_args, but just always does the
Steven Bethard steven.beth...@gmail.com added the comment:
Hence, I conclude that, unless this was spelled out in the PEP and I
missed it, that having such boundaries is a bug
Practically speaking, we just can't change this because it will break existing
argparse scripts. Argparse has had
Glenn Linderman v+pyt...@g.nevcal.com added the comment:
Ah yes, argparse had a life outside the stdlib, so now I understand your
compatibility concerns.
Mind you, I think the overall technology of argparse is superior to optparse,
which is why, together with the optparse deprecation, I am
Steven Bethard steven.beth...@gmail.com added the comment:
Thinking about it a bit more, it strikes me that maybe you could get the
behavior you want by declaring two parsers, one with just optionals, and one
with just positionals. Then:
optional_args, remaining_args =
Steven Bethard steven.beth...@gmail.com added the comment:
Actually, that could be even simpler:
args, remaining_args = optionals.parse_known_args()
args = positionals.parse_args(remaining_args, args)
--
___
Python tracker rep...@bugs.python.org
Glenn Linderman v+pyt...@g.nevcal.com added the comment:
*Very* interesting, Steven.
Looking again at section 15.4.6, and recognizing that positional arguments were
never parsed by optparse, then we discover that with two minor tweaks, removing
and add additional ArgumentParser.add_argument()
Steven Bethard steven.beth...@gmail.com added the comment:
optparse, which argparse attempts to replace, permitted positional
arguments to be intermixed with optional arguments
Sure, but optparse didn't actually parse positional arguments - it just threw
them into a bag, and then you had to
Glenn Linderman v+pyt...@g.nevcal.com added the comment:
Improved documentation would certainly help the situation.
And yes, I understand that optparse simply returned the set of positional
parameters without giving them names, types, or groups. So does getopt, and
pretty much all previous
Steven Bethard steven.beth...@gmail.com added the comment:
This behavior is intentional - positional arguments must be sequential, not
broken up with optional (flag) arguments between. So this is a documentation
bug.
Allowing positional arguments to be broken up with optional (flag) arguments
guilherme-pg guilherme.p.g...@gmail.com added the comment:
I uploaded an incomplete patch that might address the issue so it can be
discussed.
This patch introduces 'greedy_star', a new constructor parameter to
ArgumentParser that makes * positional arguments behave as expected in the
test
Glenn Linderman v+pyt...@g.nevcal.com added the comment:
Interesting that the behavior is intentional, yet it accepts positional
parameters either before, or after, or between optional (flag) parameters.
This seems to me to be a case where proper documentation of the intention would
have led
Changes by Éric Araujo mer...@netwok.org:
--
nosy: +bethard
title: argparse: nargs='*' doesn't parse all positional parameters - argparse:
nargs='*' doesn't get out-of-order positional parameters
versions: +Python 2.7, Python 3.3
___
Python tracker
15 matches
Mail list logo