[issue9352] argparse eats characters when parsing multiple merged short options

2010-11-01 Thread Steven Bethard

Steven Bethard  added the comment:

Patches applied in r86090 (3.X) and r86091 (2.7). Thanks for your help 
Catherine, and sorry it took me so long to apply these.

--
assignee:  -> bethard
resolution:  -> fixed
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9352] argparse eats characters when parsing multiple merged short options

2010-08-03 Thread Catherine Devlin

Catherine Devlin  added the comment:

Updated Steven's patch; no changes, but now it knows the new context so that 
``patch -p0`` won't fail.

--
Added file: 
http://bugs.python.org/file18343/multiple_short_same_prefix_new.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9352] argparse eats characters when parsing multiple merged short options

2010-08-03 Thread Catherine Devlin

Catherine Devlin  added the comment:

Attaching a test to verify parse failure on mismatched prefix (-abc or +abc).  
Steven's patch makes it pass.

--
nosy: +catherine
versions:  -Python 2.7, Python 3.2
Added file: 
http://bugs.python.org/file18342/test_multiple_short_same_prefix.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9352] argparse eats characters when parsing multiple merged short options

2010-07-23 Thread Steven Bethard

New submission from Steven Bethard :

[Moved from http://code.google.com/p/argparse/issues/detail?id=73]

What steps will reproduce the problem?
parser = ArgumentParser(prefix_chars="-+")
parser.add_argument("-a",action="store_true")
parser.add_argument("+b",action="store_true")
parser.add_argument("+c",action="store_true")
print parser.parse_args("-abc".split())

What is the expected output? What do you see instead?
I would expect Namespace(a=True, b=True, c=True)
You get Namespace(a=True, b=False, c=True)

because in the loop that iterates through the prefix characters it builds an 
option_string to try by pulling the first character off explicit_arg. If it 
doesn't match any option then it will try the next prefix character, but it 
will have lost that character from the explicit_arg. This is also a problem 
even with only one prefix character because if it doesn't match an option the 
error message will be missing that one character.

The above match -a, tried -b and fails, but instead of trying +b, it tries +c 
because the b has been lost.

I've included multiple_short.patch which fixes just this bug. However, I also 
don't agree with the behavior of trying all prefix characters. I would expect 
that when merging short options together they would have to all share the same 
prefix character. If I have prefix_chars="-+" and I have options -a, +a, -b, 
and +b and I type +ab I would expect my action to be called with option_strings 
+a and +b, not +a and -b. The patch to fix the above bug *and* only try the 
same prefix character as the first option is multiple_short_same_prefix.patch.

[Only the latter patch (which sounds like the right behavior) is attached. It 
will need to be updated to work against Python trunk.]

--
components: Library (Lib)
files: multiple_short_same_prefix.patch
keywords: patch
messages: 111328
nosy: bethard
priority: normal
severity: normal
stage: needs patch
status: open
title: argparse eats characters when parsing multiple merged short options
type: behavior
versions: Python 2.7, Python 3.2
Added file: http://bugs.python.org/file18147/multiple_short_same_prefix.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com