summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.8] bpo-39546: argparse: Honor allow_abbrev=False for specified ↵Miss Islington (bot)2020-02-181-28/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | prefix_chars (GH-18337) (GH-18543) When `allow_abbrev` was first added, disabling the abbreviation of long options broke the grouping of short flags ([bpo-26967](https://bugs.python.org/issue26967)). As a fix, b1e4d1b603 (contained in v3.8) ignores `allow_abbrev=False` for a given argument string if the string does _not_ start with "--" (i.e. it doesn't look like a long option). This fix, however, doesn't take into account that long options can start with alternative characters specified via `prefix_chars`, introducing a regression: `allow_abbrev=False` has no effect on long options that start with an alternative prefix character. The most minimal fix would be to replace the "starts with --" check with a "starts with two prefix_chars characters". But `_get_option_tuples` already distinguishes between long and short options, so let's instead piggyback off of that check by moving the `allow_abbrev` condition into `_get_option_tuples`. https://bugs.python.org/issue39546 (cherry picked from commit 8edfc47baec7ff4cb1b9db83dd35c8ffc1d498a4) Co-authored-by: Kyle Meyer <kyle@kyleam.com> https://bugs.python.org/issue39546 Automerge-Triggered-By: @encukou
* bpo-38821: Fix crash in argparse when using gettext (GH-17192)Miss Islington (bot)2019-11-201-2/+3
| | | | | (cherry picked from commit be5c79e0338005d675a64ba6e5b137e850d556d1) Co-authored-by: Federico Bond <federicobond@gmail.com>
* bpo-37785: Fix xgettext warning in argparse (GH-15161)Miss Islington (bot)2019-09-131-2/+3
| | | | | (cherry picked from commit 42671aea2db6cbc54369617da0fd3545048e0a45) Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
* [3.8] bpo-29553: Fix ArgumentParser.format_usage() for mutually exclusive ↵Raymond Hettinger2019-08-301-2/+8
| | | | groups (GH-14976) (GH-15494) (GH-15624)
* Steven Bethard designated a new maintainer for argparse (GH-15605) (GH-15606)Miss Islington (bot)2019-08-301-0/+1
| | | | | (cherry picked from commit 496058f59937da478eb172c864502b5dcf67705b) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
* bpo-16970: Adding error message for invalid args (GH-14844)Miss Islington (bot)2019-08-021-3/+6
| | | | | | | | | | BPO -16970: Adding error message for invalid args Applied the patch argparse-v2 patch issue 16970, ran patch check and the test suite, test_argparse with 0 errors https://bugs.python.org/issue16970 (cherry picked from commit 4b3e97592376d5f8a3b75192b399a2da1be642cb) Co-authored-by: tmblweed <tmblweed@users.noreply.github.com>
* bpo-26967: fix flag grouping with allow_abbrev=False (GH-14316) (GH-14759)Miss Islington (bot)2019-07-141-1/+1
| | | | | | | | | | | | | The `allow_abbrev` option for ArgumentParser is documented and intended to disable support for unique prefixes of --options, which may sometimes be ambiguous due to deferred parsing. However, the initial implementation also broke parsing of grouped short flags, such as `-ab` meaning `-a -b` (or `-a=b`). Checking the argument for a leading `--` before rejecting it fixes this. This was prompted by pytest-dev/pytestGH-5469, so a backport to at least 3.8 would be great :smile: And this is my first PR to CPython, so please let me know if I've missed anything! https://bugs.python.org/issue26967 (cherry picked from commit dffca9e925ee5c3072663cbe8d4d4768406d5307) Co-authored-by: Zac Hatfield-Dodds <Zac-HD@users.noreply.github.com>
* bpo-37150: Throw ValueError if FileType class object was passed in ↵Miss Islington (bot)2019-06-071-0/+4
| | | | | | | | | | | | | | | | add_argument (GH-13805) There is a possibility that someone (like me) accidentally will omit parentheses with `FileType` arguments after `FileType`, and parser will contain wrong file until someone will try to use it. Example: ```python parser = argparse.ArgumentParser() parser.add_argument('-x', type=argparse.FileType) ``` https://bugs.python.org/issue37150 (cherry picked from commit 03d5831a2d62c68654ec223168e574cd546efbf6) Co-authored-by: zygocephalus <grrrr@protonmail.com>
* bpo-23378: Add an extend action to argparse (GH-13305)Batuhan Taşkaya2019-05-211-0/+7
| | | | | | Add an extend action to argparse https://bugs.python.org/issue23378
* Remove superseded line from argparse.HelpFormatter() (GH-8839)Grant Jenks2018-08-221-1/+0
|
* bpo-13041: Use shutil.get_terminal_size() in argparse.HelpFormatter (GH-8459)Berker Peksag2018-07-251-4/+2
|
* bpo-11874: fix assertion failure in argparse metavar handling (GH-1826)wim glenn2018-06-081-1/+5
| | | | | | - bugfix and test for fragile metavar handling in argparse (see bpo-24089, bpo-14046, bpo-25058, bpo-11874) - also fixes some incorrect tests that did not make 1-element tuples correctly
* bpo-33109: argparse subparsers are once again not required by default (GH-6919)Ned Deily2018-05-241-1/+1
| | | | | | | | | bpo-26510 in 3.7.0a2 changed the behavior of argparse to make subparsers required by default, returning to the behavior of 2.7 and 3.2. The behavior was changed in 3.3 to be no longer required. While it might make more sense to have the default to required, compatibility with 3.3 through 3.6 is probably less disruptive than trying to reintroduce compatibility with 2.7 at this point. This change restores the 3.6 behavior.
* OrderedDict import is no longer needed (#4890)Raymond Hettinger2018-01-121-2/+1
|
* bpo-30152: Reduce the number of imports for argparse. (#1269)Serhiy Storchaka2017-09-251-14/+26
|
* bpo-26510: make argparse subparsers required by default (#3027)Anthony Sottile2017-09-201-0/+2
| | | | | | This fixes a regression from Python 2. To get optional subparsers, use the new parameter ``add_subparsers(required=False)``. Patch by Anthony Sottile.
* bpo-14191 Add parse_intermixed_args. (#3319)R. David Murray2017-09-071-0/+95
| | | This adds support for parsing a command line where options and positionals are intermixed as is common in many unix commands. This is paul.j3's patch with a few tweaks.
* Issue #29290: Merge 3.5.Xiang Zhang2017-01-221-1/+1
|\
| * Issue #29290: argparse help messages won't wrap at non-breaking spaces.Xiang Zhang2017-01-221-1/+1
| |
* | Issue #12713: reverted fix pending further discussion.Vinay Sajip2016-08-231-18/+5
| |
* | Closes #12713: Allowed abbreviation of subcommands in argparse.Vinay Sajip2016-08-181-5/+18
| |
* | Issue #17940: Remove redundant code from _Section.format_help()Berker Peksag2016-03-051-2/+0
| | | | | | | | | | | | | | | | | | | | | | Output of func(*args) stored in the next line: item_help = join([func(*args) for func, args in self.items]) _Section.items only used by HelpFormatter._add_item() and it looks like it doesn't have any side effects. Patch by Yogesh Chaudhari.
* | Issue #24360: Improve __repr__ of argparse.Namespace() for invalid identifiers.Berker Peksag2015-07-291-1/+7
|/ | | | Patch by Matthias Bussonnier.
* Issue #14910: Add allow_abbrev parameter to argparse.ArgumentParser.Berker Peksag2015-02-131-18/+22
| | | | Patch by Jonathan Paugh, Steven Bethard, paul j3 and Daniel Eriksson.
* Issue #23326: Removed __ne__ implementations. Since fixing default __ne__Serhiy Storchaka2015-01-311-5/+0
| | | | implementation in issue #21408 they are redundant.
* Closes #22675: fix typo.Georg Brandl2014-10-201-1/+1
|
* #9351: set_defaults on subparser is no longer ignored if set on parent.R David Murray2014-10-171-1/+8
| | | | | | | | Before, if a default was set on the parent parser, any default for that variable set via set_defaults on a subparser would be ignored. Now the subparser set_defaults is honored. Patch by Jyrki Pullianinen.
* Issue #21481: Teach argparse equality tests to return NotImplemented when ↵Raymond Hettinger2014-05-261-0/+4
| | | | comparing to unknown types.
* Issue #13107: argparse and optparse no longer raises an exception when outputSerhiy Storchaka2014-01-091-3/+5
|\ | | | | | | | | a help on environment with too small COLUMNS. Based on patch by Elazar Gershuni.
| * Issue #13107: argparse and optparse no longer raises an exception when outputSerhiy Storchaka2014-01-091-3/+5
| | | | | | | | | | a help on environment with too small COLUMNS. Based on patch by Elazar Gershuni.
* | Issue #18920: argparse's default version action (for -v, --version) shouldEli Bendersky2013-09-061-1/+2
| | | | | | | | | | | | output to stdout, matching the 'python -v' Reported by Wolfgang Maier
* | Issue #17047: remove doubled words added in 3.4,Terry Jan Reedy2013-03-111-1/+1
| | | | | | | | as reported by Serhiy Storchaka and Matthew Barnett.
* | modernize some modules' code by using with statement around open()Giampaolo Rodola'2013-02-121-4/+1
| |
* | Replace IOError with OSError (#16715)Andrew Svetlov2012-12-251-2/+2
| |
* | #11175: argparse.FileType now accepts encoding and errors arguments.Petri Lehtinen2012-12-151-3/+13
| | | | | | | | Patch by Lucas Maystre.
* | utilize yield fromPhilip Jenvey2012-10-011-2/+1
|/
* Merge 3.2 fix updates and tests for issue #15906.Barry Warsaw2012-09-121-1/+1
|\
| * Update merge from 2.7: s/basetring/strBarry Warsaw2012-09-121-1/+1
| |
| * A follow up for issue #15906: change the test for calling the type conversionBarry Warsaw2012-09-121-1/+1
| | | | | | | | | | | | | | | | on the action's default, reverting it back to previous behavior. Conversion is only done on string defaults. Add a test for this and another test that ensures such type conversions are only called once.
* | - Issue #15906: Fix a regression in argparse caused by the preceding change,Barry Warsaw2012-09-121-0/+1
|\ \ | |/ | | | | when action='append', type='str' and default=[].
| * - Issue #15906: Fix a regression in argparse caused by the preceding change,Barry Warsaw2012-09-121-0/+1
| | | | | | | | when action='append', type='str' and default=[].
* | merge #15847: allow args to be a tuple in parse_argsR David Murray2012-09-081-1/+4
|\ \ | |/ | | | | | | | | | | | | This fixes a regression introduced by the fix for issue #13922. Although args is not documented as being allowed to be a tuple, previously this worked and so naturally there are programs in the field that depend on it. Patch by Zbyszek Jędrzejewski-Szmek.
| * #15847: allow args to be a tuple in parse_argsR David Murray2012-09-081-1/+4
| | | | | | | | | | | | | | | | This fixes a regression introduced by the fix for issue #13922. Although args is not documented as being allowed to be a tuple, previously this worked and so naturally there are programs in the field that depend on it. Patch by Zbyszek Jędrzejewski-Szmek.
* | Merge #12776,#11839: call argparse type function only once.R David Murray2012-09-011-7/+19
|\ \ | |/ | | | | | | | | | | | | | | Before, the type function was called twice in the case where the default was specified and the argument was given as well. This was especially problematic for the FileType type, as a default file would always be opened, even if a file argument was specified on the command line. Patch by Arnaud Fontaine, with additional test by Mike Meyer.
| * #12776,#11839: call argparse type function only once.R David Murray2012-09-011-7/+14
| | | | | | | | | | | | | | | | | | Before, the type function was called twice in the case where the default was specified and the argument was given as well. This was especially problematic for the FileType type, as a default file would always be opened, even if a file argument was specified on the command line. Patch by Arnaud Fontaine, with additional test by Mike Meyer.
* | Merge #13922: argparse no longer incorrectly strips '--' after the first one.R David Murray2012-07-221-2/+5
|\ \ | |/ | | | | Patch by Jeff Knupp.
| * #13922: argparse no longer incorrectly strips '--' after the first one.R David Murray2012-07-221-2/+5
| | | | | | | | Patch by Jeff Knupp.
* | Merge #12353: argparse now correctly handles null argument values.R David Murray2012-07-221-1/+1
|\ \ | |/ | | | | Patch by Torsten Landschoff.
| * #12353: argparse now correctly handles null argument values.R David Murray2012-07-221-1/+1
| | | | | | | | Patch by Torsten Landschoff.
* | Merge #14391: clarify docstring discussion of Action's 'type' argument's value.R David Murray2012-07-211-4/+4
|\ \ | |/