Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

#9334: argparse does not accept options taking arguments beginning with dash (regression from optparse)

Can't Edit
Can't Publish+Mail
Start Review
Created:
7 years, 2 months ago by andersk
Modified:
4 years, 1 month ago
Reviewers:
vadmium+py
CC:
rhettinger, cben_redhat.com, amcnabb_mcnabbs.org, bethard, eric.smith, orivej_gmx.fr, eric.araujo, r.david.murray, carlosjosepita_gmail.com, tim3d.junk_gmail.com, evaned_gmail.com, andersk_mit.edu, abacabadabacaba_gmail.com, gdb_mit.edu, nelhage_nelhage.com, dremeltje_gmail.com, davidben_mit.edu, Martin Panter, paul.j3, skilletaudio_gmail.com, christophe.guillon.perso_gmail.com, danielsh, python_florianbest.de, clint.olsen_gmail.com, porton_narod.ru, maggyero, karzes_sonic.net, xtreak, fennec15_gmail.com
Visibility:
Public.

Patch Set 1 #

Total comments: 11
Unified diffs Side-by-side diffs Delta from patch set Stats Patch
Doc/library/argparse.rst View 6 chunks +61 lines, -2 lines 11 comments Download
Lib/argparse.py View 3 chunks +16 lines, -5 lines 0 comments Download
Lib/test/test_argparse.py View 2 chunks +170 lines, -1 line 0 comments Download
Misc/ACKS View 2 chunks +2 lines, -1 line 0 comments Download

Messages

Total messages: 1
Martin Panter
4 years, 1 month ago #1
https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst
File Doc/library/argparse.rst (right):

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:609: ^^^^^^^^^^^^^^^^^^^^^^^^^^
Needs a versionchanged/versionadded notice

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:612: optionals or positionals (arguments). By default,
a string starting with one of the
(arguments) is redundant (or ambiguous, depending on what you meant by it)

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:613: ``prefix_chars`` is assumed to be a command-line
option.  If ``args_default_to_positional=True``,
Regarding a string with a prefix, would it be clearer to say:

1. It is assumed to be an option even if it is in the position of an argument to
another option?

2. There are exceptions, such as nargs=REMAINDER, “-”, apparent negative
numbers?

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:615: command-line options::
Is there any advantage of leaving the flag as False? It just seems to make
things less flexible and usable, and either way the rules are rather complex.

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:619: >>> parser.add_argument('--bar', nargs=2)
I think this would be much easier to understand without the second option, and
without nargs=2.

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:621: Namespace(bar=['-one', '-two'], foo='--baz')
It would be good to ensure the arguments are not swapped around. I understand
this could be fixed by choosing names in alphabetical order.

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:625: gives an error, since ``--bar`` is defined as a
command-line option::
This is confusing. Maybe point out “--bar” is always rejected, in either mode,
otherwise it sounds like this would work when you set the flag to False.

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:631: Joining the option and value with `=` gets around
this limitation::
How to you work around this with nargs=2?

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:1404: >>> parser.test(['-1.3e4'])
parse_args?

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:1415: :class:`ArgumentParser` optional argument,
args_default_to_positional_
Drop the comma separating “optional argument, args_default_to_positional”

https://bugs.python.org/review/9334/diff/7686/Doc/library/argparse.rst#newcod...
Doc/library/argparse.rst:1425: >>> parser.parse_args(['-1', '-2-4j', '-3-4j'])
Wouldn’t it be better to contrast with the previous ['-1', '-1'] illustration?
Sign in to reply to this message.

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+