[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-07-18 Thread Michael Blahay
Michael Blahay added the comment: Ryan, I like option A as well, but it is a breaking change. Unlike in a compiled language where we could output a warning, making the proposed change could bring some software to a grinding halt. For now I'm going to make the documentation change and this is

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-06-17 Thread Michael Blahay
Michael Blahay added the comment: Need some help searching github to determine the blast radius of the proposed changes. How does one look for instances of argparse.REMAINDER that are used with a default value? -- ___ Python tracker

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-27 Thread Ryan Govostes
Ryan Govostes added the comment: Thanks Michael for all of the examples. After reading them all, I concur that "it can be hard to conceptualize what the exact behavior should be." A documentation change is warranted, at the least. However the argparse documentation, while great, is dense and

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-26 Thread Michael Blahay
Michael Blahay added the comment: Ryan, last chance, do you have any feedback? -- ___ Python tracker ___ ___ Python-bugs-list maili

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-13 Thread Michael Blahay
Michael Blahay added the comment: Ryan, What say you? Will you be satisfied with the addition of a note in the documentation? -- ___ Python tracker ___ __

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-11 Thread paul j3
paul j3 added the comment: Let me back off on that last suggestion. The problems described here and in https://bugs.python.org/issue17050 only apply to a positional. We could just add a note to the documentation to the effect. This nargs is best used as an optional as illustrated, where

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-10 Thread paul j3
paul j3 added the comment: At the start of parse_known_args, all defaults (except SUPPRESS ones) are placed in the namespace: # add any action defaults that aren't present for action in self._actions: if action.dest is not SUPPRESS: if not hasattr(n

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-10 Thread Michael Blahay
Michael Blahay added the comment: Much detail has been provided regarding why the default is ignored when user the REMAINDER option. The desire to add an exception has not. Is there anyone that can provide guidance on whether the combination of: 1. Positional Argument 2. nargs=REMAINDER 3. d

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-10 Thread Michael Blahay
Michael Blahay added the comment: With the optional arguments, the determination about whether to use the default value is made based on whether the flag is present or not. When positional arguments are involved, the need for the defaults seems to in part be determined based on whether the a

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-10 Thread Michael Blahay
Michael Blahay added the comment: Here is another take on the issue, this time illustrated through the lens of optional arguments. import argparse parser = argparse.ArgumentParser() parser.add_argument('--foo', nargs=1,default=['none']) parser.add_argument('--baz', nargs='*', default=['nada']

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-10 Thread Michael Blahay
Michael Blahay added the comment: For the purpose of facilitating continuing conversation, here are two tests that contrast the use of * versus REMAINDER import argparse parser = argparse.ArgumentParser() parser.add_argument('foo', nargs=1,default=['none']) parser.add_argument('bar', nargs=ar

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-08 Thread Michael Blahay
Michael Blahay added the comment: Ryan, I have reviewed the documentation at https://docs.python.org/3/library/argparse.html#nargs and must admit that there is not a definitive answer that I can see regarding the defined behavior should there be no command line arguments that are in fact rem

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-08 Thread Michael Blahay
Michael Blahay added the comment: Okay, so the expected output after running parse.parse_args([]) is Namespace(['nothing']) -- ___ Python tracker ___

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-07 Thread Ryan Govostes
Ryan Govostes added the comment: Just don’t run the last line which is just an echoing of the output of parser.parse_args() repeated. The Namespace type would need to be imported if you really wanted to but there’s no point. On Tuesday, May 7, 2019, Michael Blahay wrote: > > Michael Blahay a

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2019-05-07 Thread Michael Blahay
Michael Blahay added the comment: Ryan, what are the exact steps to reproduce the problem? This is what I get when I run the code you included: >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument('things', nargs=argparse.REMAINDER, default=['nothing']) _StoreAct

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2018-12-26 Thread paul j3
paul j3 added the comment: argparse.REMAINDER matches an empty list of arguments, just like '?' and '*'. So they are always 'filled', even by `parse_args([])`. '?' and '*' have some special handling of defaults in this case, see in argparse.ArgumentParser._get_values the two valu

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2018-12-14 Thread Terry J. Reedy
Change by Terry J. Reedy : -- nosy: +bethard stage: -> test needed versions: +Python 3.8 -Python 3.4, Python 3.5 ___ Python tracker ___ ___

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2018-12-14 Thread Ryan Govostes
Change by Ryan Govostes : -- versions: +Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7 ___ Python tracker ___ ___ Python

[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument

2018-12-14 Thread Ryan Govostes
New submission from Ryan Govostes : import argparse parser = argparse.ArgumentParser() parser.add_argument('things', nargs=argparse.REMAINDER, default=['nothing']) parser.parse_args([]) >>> Namespace(things=[]) Since there were no unparsed arguments remaining, the `default` setting for `things