summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
Commit message (Collapse)AuthorAgeFilesLines
* argparse: Remove unused name variable when handling ArgumentTypeError (#96549)Jonathon Reinhart2022-09-051-1/+0
| | | | | | | | This removes the unused `name` variable in the block where `ArgumentTypeError` is handled. `ArgumentTypeError` errors are handled by showing just the string of the exception; unlike `ValueError`, the name (`__name__`) of the function is not included in the error message. Fixes #96548
* gh-92445 Improve interaction between nargs="*" and choices() (GH-92565)Harry2022-08-251-1/+3
|
* gh-85308: argparse: Use filesystem encoding for arguments file (GH-93277)Inada Naoki2022-06-231-1/+3
|
* Allow translating argument error messages (#17169)DjMorgul2022-05-051-1/+1
|
* gh-88753: Make BooleanOptionalAction's addition of default to help more ↵Toshio Kuratomi2022-05-031-5/+15
| | | | | | | | | | | | | | | | similar to other actions (#27808) Help for other actions omit the default value if default is SUPPRESS or already contains the special format string '%(default)'. Add those special cases to BooleanOptionalAction's help formatting too. Fixes https://bugs.python.org/issue44587 so that default=SUPPRESS is not emitted. Fixes https://bugs.python.org/issue38956 as this code will detect whether '%(default)s' has already been specified in the help string. Signed-off-by: Micky Yun Chan (michiboo): <chanmickyyun@gmail.com> Co-authored-by: Micky Yun Chan <michan@redhat.com>
* bpo-39716: Raise on conflicting subparser names. (GH-18605)Antony Lee2022-05-011-0/+7
| | | | | | | | | | | Raise an ArgumentError when the same subparser name is added twice to an ArgumentParser. This is consistent with the (default) behavior when the same option string is added twice to an ArgumentParser. (Support for `conflict_handler="resolve"` could be considered as a followup feature, although real use cases seem even rarer than "resolve"ing option-strings.) Automerge-Triggered-By: GH:rhettinger
* gh-91832: Add 'required' attr to argparse.Action repr (GH-91841)Abhigyan Bose2022-04-281-0/+1
| | | | | | | | | # Adding 'required' to names in Lib.argparse.Action gh-91832: Added 'required' to the list `names` in `Lib.argparse.Action`. Changed constant strings that test the Action object. Automerge-Triggered-By: GH:merwok
* Revert "gh-85567: Register a cleanup function to close files for FileType ↵Victor Stinner2022-04-211-7/+3
| | | | | objects in argparse (#32257)" (#91771) This reverts commit 328dbc051f84bd5fdf61101bb4fa61d85f8b7feb.
* gh-85567: Register a cleanup function to close files for FileType objects in ↵achhina2022-04-181-3/+7
| | | | | | | argparse (#32257) * bpo-41395: Register a cleanup function to close files for FileType objects in argparse * Added import as top level import, and renamed file as fh.
* bpo-14156: Make argparse.FileType work correctly for binary file modes when ↵MojoVampire2022-03-061-4/+4
| | | | | | | argument is '-' (GH-13165) Also made modes containing 'a' or 'x' act the same as a mode containing 'w' when argument is '-' (so 'a'/'x' return sys.stdout like 'w', and 'ab'/'xb' return sys.stdout.buffer like 'wb').
* bpo-46510: update Python2-style exception handling in argparse (GH-30881)Kumar Aditya2022-01-251-6/+4
|
* bpo-46080: fix argparse help generation exception in edge case (GH-30111)Felix Fontein2022-01-201-1/+1
| | | | | Fix an uncaught exception during help text generation when argparse.BooleanOptionalAction is used with default=argparse.SUPPRESS and help is specified.
* argparse docs: prog default is the basename of argv[0] (GH-30298)Jade Lovelace2022-01-021-1/+2
|
* bpo-22047: [argparse] deprecate nested argument groups and mutually ↵Irit Katriel2021-12-161-0/+18
| | | | exclusive groups (GH-30098)
* bpo-26952: [argparse] clearer error when formatting an empty mutually… ↵Irit Katriel2021-12-151-0/+3
| | | | (GH-30099)
* bpo-45235: Revert an argparse bugfix that caused a regression (GH-29525)Raymond Hettinger2021-11-121-7/+6
| | | | | * Revert "bpo-45235: Fix argparse overrides namespace with subparser defaults (GH-28420) (GH-28443)" This reverts commit a18d52269ab6071a605d6c72f6af585a4c533ca4.
* bpo-24444: fix an error in argparse help when help for an option is blank ↵andrei kulakov2021-10-131-5/+6
| | | | (GH-28050)
* bpo-45235: Fix argparse overrides namespace with subparser defaults (GH-28420)Adam Schwalm2021-09-181-6/+7
|
* bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672)Maximilian Hils2021-08-161-1/+1
| | | | Co-authored-by: Micky Yun Chan <michan@redhat.com>
* bpo-37880: for argparse add_argument with action='store_const', const now ↵Jack DeVries2021-07-311-2/+3
| | | | defaults to None. (GH-26707)
* bpo-29298: Fix crash with required subparsers without dest (GH-3680)Anthony Sottile2021-07-231-0/+2
| | | Automerge-Triggered-By: GH:encukou
* bpo-9694: Fix misleading phrase "optional arguments" (GH-23858)Raymond Hettinger2020-12-231-1/+1
|
* bpo-40862: Raise TypeError when const is given to ↵Rémi Lapeyre2020-06-051-1/+0
| | | | argparse.BooleanOptionalAction (GH-20623)
* bpo-39058: Preserve attribute order in argparse Namespace reprs. (GH-17621)Raymond Hettinger2020-05-181-1/+1
|
* bpo-39546: argparse: Honor allow_abbrev=False for specified prefix_chars ↵Kyle Meyer2020-02-181-28/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | (GH-18337) 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
* Defer import of shutil which only needed for help and usage (GH-17334)Raymond Hettinger2019-11-221-3/+3
|
* bpo-38821: Fix crash in argparse when using gettext (GH-17192)Federico Bond2019-11-201-2/+3
|
* bpo-38438: Simplify argparse "star nargs" usage. (GH-17106)Brandt Bucher2019-11-111-1/+5
|
* bpo-8538: Add support for boolean actions to argparse (GH-11478)Rémi Lapeyre2019-09-131-1/+46
| | | Co-Authored-By: remilapeyre <remi.lapeyre@henki.fr>
* bpo-37785: Fix xgettext warning in argparse (GH-15161)Jakub Kulík2019-09-131-2/+3
|
* bpo-9938: Add optional keyword argument exit_on_error to ↵Hai Shi2019-09-121-9/+17
| | | | | | | | | | | | argparse.ArgumentParser (GH-15362) Co-Authored-by: Xuanji Li <xuanji@gmail.com> https://bugs.python.org/issue9938 Automerge-Triggered-By: @matrixise
* Steven Bethard designated a new maintainer for argparse (GH-15605)Raymond Hettinger2019-08-301-0/+1
|
* bpo-29553: Fix ArgumentParser.format_usage() for mutually exclusive groups ↵Flavian Hautbois2019-08-251-2/+8
| | | | | (GH-14976) Co-authored-by: Andrew Nester <andrew.nester.dev@gmail.com>
* bpo-16970: Adding error message for invalid args (GH-14844)tmblweed2019-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
* bpo-26967: fix flag grouping with allow_abbrev=False (GH-14316)Zac Hatfield-Dodds2019-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/pytest#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
* Remove redundant if check from optional argument function in argparse. (GH-8766)Shashank Parekh2019-06-211-4/+2
|
* bpo-37150: Throw ValueError if FileType class object was passed in ↵zygocephalus2019-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
* 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
| |