[issue16878] argparse: positional args with nargs='*' defaults to []

2020-11-06 Thread Irit Katriel
Change by Irit Katriel : -- versions: +Python 3.10, Python 3.8, Python 3.9 -Python 2.7, Python 3.2, Python 3.3, Python 3.4 ___ Python tracker ___ _

[issue16878] argparse: positional args with nargs='*' defaults to []

2018-10-16 Thread sebix
Change by sebix : -- nosy: +sebix ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mai

[issue16878] argparse: positional args with nargs='*' defaults to []

2014-07-15 Thread paul j3
paul j3 added the comment: The documentation patch here should note that a positional '*' string default is not parsed (i.e. does not pass through _get_value). (see http://bugs.python.org/issue17250) -- ___ Python tracker

[issue16878] argparse: positional args with nargs='*' defaults to []

2013-09-18 Thread paul j3
paul j3 added the comment: On a related point, the 'action.required' value is set differently for '?' and '*' positionals. if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]: kwargs['required'] = True if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs:

[issue16878] argparse: positional args with nargs='*' defaults to []

2013-04-17 Thread paul j3
paul j3 added the comment: In this example: >>> p.add_argument('--foo', nargs='*', default=None) >>> p.parse_args([]) Namespace(foo=None) >>> p.parse_args(['--foo']) Namespace(foo=[]) 'p.parse_args([])' just assigns the default to 'foo' in the Namespace. "p.parse_args(['--f

[issue16878] argparse: positional args with nargs='*' defaults to []

2013-01-09 Thread Chris Jerdonek
Chris Jerdonek added the comment: It turns out that there is already a test case: http://hg.python.org/cpython/file/05183ce544be/Lib/test/test_argparse.py#l799 (at the line "('', NS(foo=[])),") I've updated the patch with a note to reflect this. -- Added file: http://bugs.python.org/f

[issue16878] argparse: positional args with nargs='*' defaults to []

2013-01-07 Thread Chris Jerdonek
Chris Jerdonek added the comment: Attached is a doc patch. I also improved some other aspects of the *default* section while I was there. We should probably make sure a test exists for the newly-documented behavior (i.e. for passing no arguments for a positional argument with nargs='*' and d

[issue16878] argparse: positional args with nargs='*' defaults to []

2013-01-06 Thread Chris Jerdonek
Chris Jerdonek added the comment: I was referring to the fact that optionals have an additional case that positionals don't have: "Note that for optional arguments, there is an additional case -- the option string is present but not followed by a command-line argument." (from http://docs.pyth

[issue16878] argparse: positional args with nargs='*' defaults to []

2013-01-06 Thread R. David Murray
R. David Murray added the comment: >>> p.add_argument('-a', action="append", default=None) >>> p.parse_args([]) Namespace(a=None) >>> p.parse_args(['-a', '1', '-a', '2']) Namespace(a=['1', '2']) So there's a logical correspondence there (repeated option vs multiple values, each producing a list

[issue16878] argparse: positional args with nargs='*' defaults to []

2013-01-06 Thread Chris Jerdonek
Chris Jerdonek added the comment: I agree it would be very likely to break working code. Can you elaborate on your point about 'append' though? I'm not sure I see it. Aside from consistency, I'm wondering if there is ever a case where it would help to return None for positional arguments. F

[issue16878] argparse: positional args with nargs='*' defaults to []

2013-01-06 Thread R. David Murray
R. David Murray added the comment: I'd prefer to fix it, since having the action='append' and nargs='*' behaviors be different looks like a bug. However, fixing it to match 'append' (default really is None) would be likely to break working code, so we certainly couldn't backport that, and I'd

[issue16878] argparse: positional args with nargs='*' defaults to []

2013-01-06 Thread Chris Jerdonek
New submission from Chris Jerdonek: In argparse, positional arguments with nargs='*' default to [] rather None, even if default=None is passed explicitly. The documentation says otherwise: "The default keyword argument of add_argument(), whose value defaults to None, specifies what value shou