[issue13922] argparse handling multiple -- in args improperly

2014-07-07 Thread paul j3

paul j3 added the comment:

http://bugs.python.org/issue9571 proposes a refinement to this patch - drop the 
'--' from PARSER and REMAINDER nargs if it is the 1st string.

--

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



[issue13922] argparse handling multiple -- in args improperly

2013-04-19 Thread Michele Orrù

Changes by Michele Orrù maker...@gmail.com:


--
nosy: +maker

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



[issue13922] argparse handling multiple -- in args improperly

2013-04-14 Thread paul j3

paul j3 added the comment:

This patch removes only one '--', the one that put a '-' in the 
'arg_strings_pattern'.  It does this in 'consume_positionals' right before 
calling 'take_action'.  As before it does not do this if nargs is PARSER or 
REMAINDER.

test_argparse.py has two DoubleDashRemoval cases, that attempt to highlight the 
changes from production (delete all --) and development (delete first -- in 
each positional group) versions.

I have not made any changes to the documentation.  All it says now is:

If you have positional arguments that must begin with - and don’t look like 
negative numbers, you can insert the pseudo-argument '--' which tells 
parse_args() that everything after that is a positional argument:

--
Added file: http://bugs.python.org/file29845/dbldash.patch

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



[issue13922] argparse handling multiple -- in args improperly

2013-04-06 Thread paul j3

paul j3 added the comment:

I am working on an alternative solution that moves the '--' removal to the 
consume_positionals() method, and only does it if there is a corresponding '-' 
in the arg_strings_pattern.

--

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



[issue13922] argparse handling multiple -- in args improperly

2013-04-05 Thread paul j3

paul j3 added the comment:

There are several problems with the patch provided in msg156315

This description:

Added patch so that only the first '--' is removed by an argparse.PARSE or 
argparse.REMAINDER argument.

should read

Added patch so that only the first '--' is removed by arguments that are not 
argparse.PARSER or argparse.REMAINDER .

The test that adds a third subparser with a nargs='...' argument does not test 
this change.   It exercises both nargs types that are not affected by the 
change in argparse.py.  As such older versions of argparse pass this test.

I thinking argparse.py change is correct (delete only the 1st '--'), though I'm 
not sure it addresses the concern of the original poster.

--
nosy: +paul.j3

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



[issue13922] argparse handling multiple -- in args improperly

2013-04-05 Thread paul j3

paul j3 added the comment:

There's another 'feature' to the patch proposed here.  It only deletes the 
first '--' in the list of strings passed to '_get_values' for a particular 
action.

parser = argparse.ArgumentParser()
parser.add_argument('foo')
parser.add_argument('bar', nargs='*')
print(parser.parse_args('-- 1 -- 2 3 4'.split(' ')))
# Namespace(bar=['2', '3', '4'], foo='1')

'_get_values' first gets ('foo',['--','1']), then ('bar',['--','2','3','4'])

print(parser.parse_args('-- -- 1 -- 2 -- 3 4'.split(' ')))
# with this '1st only' change
# Namespace(bar=['1', '2', '--', '3', '4'], foo='--')
# without it, deleting all '--'; note foo is empty
# Namespace(bar=['1', '2', '3', '4'], foo=[])

And to confuse things a bit more:

print(parser.parse_args('1 -- 2 3 4'.split(' ')))
# Namespace(bar=['2', '3', '4'], foo='1')

passes ['1','--'] with 'foo'

If 'bar' nargs='...', bar gets all of the '--' (with or without this patch).

The handling of '--' is complex because it is used in one place to mean, 
'everything else is an argument', effectively adding '-AA...' to the 
arg_strings_pattern. It also matches with the nargs_pattern (e.g. 
'(-*A-*)...').  And then it may or may not be removed in _get_values().

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-09-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 5d8454fcc629 by R David Murray in branch '3.2':
#15847: allow args to be a tuple in parse_args
http://hg.python.org/cpython/rev/5d8454fcc629

New changeset 76655483c5c8 by R David Murray in branch 'default':
merge #15847: allow args to be a tuple in parse_args
http://hg.python.org/cpython/rev/76655483c5c8

New changeset a2147bbf7868 by R David Murray in branch '2.7':
#15847: allow args to be a tuple in parse_args
http://hg.python.org/cpython/rev/a2147bbf7868

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-08-21 Thread George-Cristian Bîrzan

George-Cristian Bîrzan added the comment:

This patch introduced a regression. Before, parse_args would take a tuple as an 
argument, and in _get_values it was converted to a list via list comprehension, 
which meant it was working with tuples too. In the current version, that raises 
an AttributeError, since tuples do not have .remove().

The simplest solution would be to convert arg_strings to a list before calling 
.remove(). The downside is that it will break silently when you pass it a 
string, whereas now you get a confusing error message (but, this is the same 
behavior as before this fix)

--
nosy: +gcbirzan

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



[issue13922] argparse handling multiple -- in args improperly

2012-08-21 Thread Steven Bethard

Steven Bethard added the comment:

@gcbirzan: Could you please open up a new issue? The current issue is fixed - 
it's just that the fix caused a new issue.

I would say that the `args` parameter was never intended to be anything but a 
list, so currently there's a documentation bug since that isn't stated 
explicitly anywhere. (But certainly the tests only test for lists, not any 
other sequences.)

Adding support for stuff other than lists feels more like a feature request, 
but given that it apparently worked by accident before, I guess we need to 
treat it as a bug. Probably the fix for that bug needs to have a ton of tests 
that check whether tuples work in all the various ways that parse_args is used.

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-07-21 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

This patch looks like the right fix to me. The tests look good too.

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-07-21 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 18b114be013e by R David Murray in branch '3.2':
#13922: argparse no longer incorrectly strips '--' after the first one.
http://hg.python.org/cpython/rev/18b114be013e

New changeset bd2c167dfabc by R David Murray in branch '2.7':
#13922: argparse no longer incorrectly strips '--' after the first one.
http://hg.python.org/cpython/rev/bd2c167dfabc

New changeset a636f365d815 by R David Murray in branch 'default':
Merge #13922: argparse no longer incorrectly strips '--' after the first one.
http://hg.python.org/cpython/rev/a636f365d815

--
nosy: +python-dev

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



[issue13922] argparse handling multiple -- in args improperly

2012-07-21 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

Committed.  Thanks, Jeff.  By the way, although this patch isn't big enough to 
require it, it would be great if you would submit a contributor agreement: 
http://www.python.org/psf/contrib.

--
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

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



[issue13922] argparse handling multiple -- in args improperly

2012-07-21 Thread Warren Turkal

Warren Turkal w...@penguintechs.org added the comment:

Thanks for fixing this issue. You guys are great!

wt

On Sat, Jul 21, 2012 at 8:00 PM, R. David Murray rep...@bugs.python.orgwrote:


 R. David Murray rdmur...@bitdance.com added the comment:

 Committed.  Thanks, Jeff.  By the way, although this patch isn't big
 enough to require it, it would be great if you would submit a contributor
 agreement: http://www.python.org/psf/contrib.

 --
 resolution:  - fixed
 stage:  - committed/rejected
 status: open - closed

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue13922
 ___


--

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



[issue13922] argparse handling multiple -- in args improperly

2012-03-18 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

I think it is unlikely that anyone depends on argparse consuming multiple -- 
strings.  If you are worried about it we could restrict the change to 3.3.  But 
personally I think this would be OK for a bug fix.

--
nosy: +r.david.murray
versions:  -Python 3.4

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



[issue13922] argparse handling multiple -- in args improperly

2012-03-18 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

Ok, I agree - I'm fine with it as a bugfix. Depending on the removal of extra 
-- strings would be pretty crazy anyway. ;-)

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-03-18 Thread Jeff Knupp

Jeff Knupp jkn...@gmail.com added the comment:

I don't know that this is a bug. Rather, the string '--' means different things 
to argparse and optparse. In argparse, '--' is a psuedo-argument taken to mean 
everything after this is a postional argument and not stop processing 
arguments, which is the optparse meaning. In that context it doesn't seem like 
removing additional '--' is a bug in argparse, since additional '--' would 
merely be restating the same thing.

--
nosy: +Jeff.Knupp

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



[issue13922] argparse handling multiple -- in args improperly

2012-03-18 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

No, it is definitely a bug.  It prevents implementing parsers that pass strings 
on to another sub-parser or command.  Imagine, for example, implementing a 
script that takes some arguments, but takes the entire rest of the command 
string and passes it to some unix program that it calls...and that unix program 
will recognize '--' in that string as the end of processing *its* options, and 
the user of the python command may well want to do that.  Unless this bug is 
fixed, it would be impossible to use argparse to implement such a reasonable 
scenario.

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-03-18 Thread Eric V. Smith

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

I agree with David. It's a bug. I have programs (not using argparse yet) that 
do exactly what he describes.

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-03-18 Thread Jeff Knupp

Jeff Knupp jkn...@gmail.com added the comment:

In that case, wouldn't you use 'parse_known_args' instead of 'parse_args'
and pass the remaining arguments to the next script? This case is
explicitly mentioned in the argparse documentation. Again it seems to me
that the meaning of '--' has changed slightly between optparse and
argparse. Whether or not that was correct or intended is perhaps another
isssue.

On Sun, Mar 18, 2012 at 1:32 PM, Eric V. Smith rep...@bugs.python.orgwrote:


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

 I agree with David. It's a bug. I have programs (not using argparse yet)
 that do exactly what he describes.

 --

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue13922
 ___


--

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



[issue13922] argparse handling multiple -- in args improperly

2012-03-18 Thread Eric V. Smith

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

No. parse_known_args assumes you have known and unknown args intermixed. 

Going back to the original example, what if hack and :target had 
overlapping parameter names (say, they both supported --arg1)? I think 
parse_known_args would pick up all instances of --arg1. I really want -- to 
mean treat everything else as non-optional arguments.

Whether that's the original intent, I don't know. But as David says, unless it 
is, it's impossible to implement such a scheme with argparse.

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-03-18 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

 It prevents implementing parsers that pass strings on to another 
 sub-parser or command.
...
 wouldn't you use 'parse_known_args' instead of 'parse_args'
 and pass the remaining arguments to the next script

I'll just say again that the recommended way of passing arguments to another 
command is via nargs=argparse.REMAINDER. (Though you may still need -- if the 
first argument in the remainder is a flag shared by your parser, as Warren 
Turka pointed out.)

 I really want -- to mean treat everything else as non-optional 
 arguments

Yep, and that's what it's intended to mean, and what the documentation says:

you can insert the pseudo-argument '--' which tells parse_args() that 
everything after that is a positional argument
http://docs.python.org/library/argparse.html#arguments-containing

It's therefore a bug if there's a '--' after the first '--', but it's not being 
treated as a positional argument.

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-03-18 Thread Jeff Knupp

Jeff Knupp jkn...@gmail.com added the comment:

Added patch so that only the first '--' is removed by an argparse.PARSE or 
argparse.REMAINDER argument. Note that, as Steven said, argparse.REMAINDER 
should be used in the OP's issue (and the added test makes sure all remaining 
arguments are preserved even if they appear in the parent parser).

--
keywords: +patch
Added file: http://bugs.python.org/file24936/argparse.patch

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



[issue13922] argparse handling multiple -- in args improperly

2012-02-15 Thread Warren Turkal

Warren Turkal w...@penguintechs.org added the comment:

Using argparse.REMAINDER will not help for my problem in my real program as the 
first arg needs to be handled by my program and mapped into the real binary 
name.

If I recall correctly from memory, the following is what happened when I tried 
using argparse.REMAINDER. If call my program like so:
$ hack run :target --help

The subcommand will be run in this case. Because :target is handled by 
argparse, the --help will not be seen as part of the remainder of the 
arguments, and I will get the help for the hack run subcommand instead of the 
target binary getting the --help argument. I have pushed most of the program to 
[1] if you want to take a look. Specifically, see cli/commands/run.py:do_run 
for that bit of code that handles the run subcommand.

[1]https://github.com/wt/repo-digg-dev-hackbuilder

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-02-13 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

See nargs=argparse.REMAINDER for an approach that doesn't require that first 
'--':

http://docs.python.org/library/argparse.html#nargs

But yeah, removing more than one '--' is probably a bug. Fixing it would be a 
little backwards incompatible though. Is it possible that anyone actually 
depends on the behavior of consuming multiple '--' arguments?

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-02-10 Thread Christophe Kalt

Christophe Kalt k...@taranis.org added the comment:

Hah.. was just about to report this.  I'm in the midst of converting a bunch of 
scripts from optparse to argparse, and this is one of the problems I'm hitting.

--
nosy: +kalt

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



[issue13922] argparse handling multiple -- in args improperly

2012-02-10 Thread Warren Turkal

Changes by Warren Turkal w...@penguintechs.org:


--
versions: +Python 3.3, Python 3.4

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



[issue13922] argparse handling multiple -- in args improperly

2012-02-04 Thread Warren Turkal

Warren Turkal w...@penguintechs.org added the comment:

I wanted to include a minimal example script, so here it is. If you run this 
like so:
$ ./test.py -- blah -- blah2

you will get the the following output:
Namespace(args=['blah2'], target=['blah'])

I would have expected the following instead:
Namespace(args=['--', 'blah2'], target=['blah'])

--

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



[issue13922] argparse handling multiple -- in args improperly

2012-02-04 Thread Warren Turkal

Warren Turkal w...@penguintechs.org added the comment:

It doesn't look like that file got included last time, so here's a second try.

--
Added file: http://bugs.python.org/file24424/test.py

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



[issue13922] argparse handling multiple -- in args improperly

2012-02-02 Thread Eric V. Smith

Changes by Eric V. Smith e...@trueblade.com:


--
nosy: +bethard, eric.smith

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



[issue13922] argparse handling multiple -- in args improperly

2012-02-01 Thread Warren Turkal

New submission from Warren Turkal w...@penguintechs.org:

I have a program that runs something like the following:
$ hack run -- :target --arg1 --arg2 arg3 arg4

This basically runs a program identified by :target with the args. However, I 
cannot pass -- to the program. For example, if I type:
$ hack run -- :hack run -- :target clean --help

the second -- is swallowed by the parser, and I get an the help for hack 
run instead of instead of hack clean. The run subcommand just does the 
following:

all_args = [target.bin_path] + args.args
os.execv(target.bin_path, all_args)

However, the first hack run has the following list for args:
args = Namespace(args=['run', ':hack', 'clean', '--help'], func=function 
do_run at 0x19c3e60, target=':hack')

Where is the second --? I would have expected the args list to be:
args=['run', '--', ':hack', 'clean', '--help']

About the python version, I am using python 2.6. However, I am using the latest 
release of argparse from [1] and am assuming that it's very similar code.

[1]http://code.google.com/p/argparse/downloads/list

--
messages: 152443
nosy: Warren.Turkal
priority: normal
severity: normal
status: open
title: argparse handling multiple -- in args improperly
type: behavior
versions: Python 2.7, Python 3.2

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