[issue9182] argparse: optional argument w/ narg='+' conflicts w/ positional argsument

2010-07-06 Thread Sergey Konoplev

New submission from Sergey Konoplev gray...@gmail.com:

Hello,

I am starting to use argparse package and faced the problem where an optional 
argument w/ nargs='+' conflicts w/ a positional argument. 

Here is the test case:

 import argparse
 p = argparse.ArgumentParser()
 p.add_argument('foo', type=str)
_StoreAction(option_strings=[], dest='foo', nargs=None, const=None, 
default=None, type=type 'str', choices=None, help=None, metavar=None)
 p.add_argument('-b', '--bar', type=int, nargs='+')
_StoreAction(option_strings=['-b', '--bar'], dest='bar', nargs='+', const=None, 
default=None, type=type 'int', choices=None, help=None, metavar=None)
 p.print_help()
usage: [-h] [-b BAR [BAR ...]] foo

positional arguments:
  foo

optional arguments:
  -h, --helpshow this help message and exit
  -b BAR [BAR ...], --bar BAR [BAR ...]
 p.parse_args('-b 123 456 bla'.split())
usage: [-h] [-b BAR [BAR ...]] foo
: error: argument -b/--bar: invalid int value: 'bla'


It prints this usage string usage: [-h] [-b BAR [BAR ...]] foo so it is 
assumed that I could use this  -b 123 456 bla but it does not works. 

How could it be and how to solve it? 

Thank you in advance.

--
components: Library (Lib)
messages: 109402
nosy: gray_hemp
priority: normal
severity: normal
status: open
title: argparse: optional argument w/ narg='+' conflicts w/ positional argsument
type: behavior
versions: Python 2.6

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



[issue9182] argparse: optional argument w/ narg='+' conflicts w/ positional argsument

2010-07-06 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Thanks for the bug report. Can you try separating option arguments from 
positional arguments with “--”? If yes, this would be a doc bug.

Also, can you reproduce it with Python 2.7?

--
nosy: +merwok

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



[issue9182] argparse: optional argument w/ narg='+' conflicts w/ positional argsument

2010-07-06 Thread Eric Smith

Eric Smith e...@trueblade.com added the comment:

I get the same behavior in 2.7. Adding '--', I get:

 p.parse_args('-b 123 456 -- bla'.split())
Namespace(bar=[123, 456], foo='bla')

Which is what I expect.

Éric: From your comment, I'm not sure if you think it's a doc bug because '--' 
does work, or because it doesn't work without it. But I think it's working as 
designed. I'm closing this. If you think it's a doc bug, please reopen and 
change to the Documentation component.

--
nosy: +eric.smith
resolution:  - invalid
status: open - closed
versions: +Python 2.7

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



[issue9182] argparse: optional argument w/ narg='+' conflicts w/ positional argsument

2010-07-06 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

I was suggesting a doc bug only if the current doc didn’t advertise clearly 
this way of combining nargs with positional arguments. Using “--” is most 
certainly standard and right, 

Using “--” to explicitly signal positional arguments is most certainly right 
and standard, but people have to read about that for the first time somewhere. 
In a perfect world, that would be in their shell’s man page, but better add a 
word about it in the reference. The “--” marker is actually mentioned in one 
section: http://docs.python.org/dev/library/argparse#arguments-containing

I’m reopening, suggesting that a line be added to explain the standard “--” 
separator for use cases like Sergey’s.

--
assignee:  - d...@python
components: +Documentation -Library (Lib)
nosy: +d...@python
resolution: invalid - 
stage:  - needs patch
status: closed - open

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



[issue9182] argparse: optional argument w/ narg='+' conflicts w/ positional argsument

2010-07-06 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Duh, please ignore the first two lines, I forgot to remove them after 
rephrasing my comment. Sorry.

--

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



[issue9182] argparse: optional argument w/ narg='+' conflicts w/ positional argsument

2010-07-06 Thread Fred L. Drake, Jr.

Fred L. Drake, Jr. fdr...@acm.org added the comment:

On Tue, Jul 6, 2010 at 4:33 PM, Éric Araujo rep...@bugs.python.org wrote:
 Using “--” to explicitly signal positional arguments is most certainly
 right and standard, but people have to read about that for the first
 time somewhere. In a perfect world, that would be in their shell’s man
 page, but better add a word about it in the reference.

It's a convention; not all applications in the larger world support it at all.

It needs to be documented for argparse, and also for specific applications
(which may or may not be built using argparse or Python.

This does not belong in the shell documentation unless needed for the shell
itself.

--
nosy: +fdrake

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