| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
| |
ArgumentParser.add_subparsers() (GH-27667)
Call _() on literal strings only.
|
|
|
|
| |
groups (GH-113085)
|
|
|
|
| |
Fix parsing positional argument with nargs equal to '?' or '*' if it is
preceded by an option and another positional argument.
|
|
|
|
|
|
|
| |
(GH-124306)
This allows to use positional argument with nargs='*' and without default
in mutually exclusive group and improves error message about required
arguments.
|
|
|
|
| |
in argparse (GH-124275)
|
|
|
|
|
|
| |
Arguments with the value identical to the default value (e.g. booleans,
small integers, empty or 1-character strings) are no longer considered
"not present".
|
|
|
|
|
|
|
|
| |
In case of usage a long command along with max_help_position more than
the length of the command, the command's help was incorrectly started
on the new line.
Co-authored-by: Pavel Ditenbir <pavel.ditenbir@gmail.com>
|
|
|
| |
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
|
|
|
|
|
| |
Only the first one has now been removed, all subsequent ones are now
taken literally.
|
|
|
|
|
|
|
|
| |
underscores (#123970)
---------
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
|
|
|
|
| |
mutually exclusive groups (GH-121159)
|
|
|
|
|
|
|
|
|
| |
(GH-121056)
* parse_intermixed_args() now raises ArgumentError instead of calling
error() if exit_on_error is false.
* Internal code now always raises ArgumentError instead of calling
error(). It is then caught at the higher level and error() is called if
exit_on_error is true.
|
|
|
|
| |
instead of exiting when given unrecognized arguments (GH-121019)
|
|
|
|
|
| |
(#118806)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Rationale
=========
argparse performs a complex formatting of the usage for argument grouping
and for line wrapping to fit the terminal width. This formatting has been
a constant source of bugs for at least 10 years (see linked issues below)
where defensive assertion errors are triggered or brackets and paranthesis
are not properly handeled.
Problem
=======
The current implementation of argparse usage formatting relies on regular
expressions to group arguments usage only to separate them again later
with another set of regular expressions. This is a complex and error prone
approach that caused all the issues linked below. Special casing certain
argument formats has not solved the problem. The following are some of
the most common issues:
- empty `metavar`
- mutually exclusive groups with `SUPPRESS`ed arguments
- metavars with whitespace
- metavars with brackets or paranthesis
Solution
========
The following two comments summarize the solution:
- https://github.com/python/cpython/issues/82091#issuecomment-1093832187
- https://github.com/python/cpython/issues/77048#issuecomment-1093776995
Mainly, the solution is to rewrite the usage formatting to avoid the
group-then-separate approach. Instead, the usage parts are kept separate
and only joined together at the end. This allows for a much simpler
implementation that is easier to understand and maintain. It avoids the
regular expressions approach and fixes the corresponding issues.
This closes the following GitHub issues:
- #62090
- #62549
- #77048
- #82091
- #89743
- #96310
- #98666
These PRs become obsolete:
- #15372
- #96311
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(#116162)
When parsing positional vs optional arguments, the use of min with a
list comprehension inside of a loop results in quadratic time based
on the number of optional arguments given. When combined with use of
prefix based argument files and a large number of optional flags, this
can result in extremely slow parsing behavior.
This replaces the min call with a simple loop with a short circuit to
break at the next optional argument.
Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
|
| |
|
|
|
|
|
|
|
| |
(GH-12711)
Co-authored-by: paul.j3
Co-authored-by: Jérémie Detrey <jdetrey@users.noreply.github.com>
|
|
|
|
|
|
|
|
|
|
|
| |
exclusive group are suppressed (GH-96311)
Reproducer depends on terminal size - the traceback occurs when there's
an option long enough so the usage line doesn't fit the terminal width.
Option order is also important for reproducibility.
Excluding empty groups (with all options suppressed) from inserts
fixes the problem.
|
|
|
|
|
| |
(GH-101591)
Signed-off-by: FeRD (Frank Dana) <ferdnyc@gmail.com>
|
|
|
|
| |
ArgumentParser.parse_known_args() (GH-114180)
|
|
|
|
| |
argparse (GH-114086)
|
|
|
| |
For example "--option=--".
|
|
|
|
|
|
|
|
|
|
|
| |
If the option with argument has short and long names,
output argument only once, after the long name:
-o, --option ARG description
instead of
-o ARG, --option ARG description
|
| |
|
|
|
|
|
| |
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
|
|
|
|
|
|
|
|
| |
`argparse.BooleanOptionalAction` (#103678)
Co-authored-by: Kirill <80244920+Eclips4@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
|
| |
|
|
|
|
|
|
| |
* In particular, don't exit when trying to print to stderr = None.
* Add tests
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
|
|
|
|
| |
add_argument() were dropped (#102318)
|
|
|
|
|
| |
Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
|
|
|
|
|
|
|
|
| |
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
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
| |
# 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
|
|
|
|
|
| |
objects in argparse (#32257)" (#91771)
This reverts commit 328dbc051f84bd5fdf61101bb4fa61d85f8b7feb.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
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').
|
| |
|
|
|
|
|
| |
Fix an uncaught exception during help text generation when
argparse.BooleanOptionalAction is used with default=argparse.SUPPRESS
and help is specified.
|
| |
|
|
|
|
| |
exclusive groups (GH-30098)
|
|
|
|
| |
(GH-30099)
|
|
|
|
|
| |
* Revert "bpo-45235: Fix argparse overrides namespace with subparser defaults (GH-28420) (GH-28443)"
This reverts commit a18d52269ab6071a605d6c72f6af585a4c533ca4.
|
|
|
|
| |
(GH-28050)
|
| |
|
|
|
|
| |
Co-authored-by: Micky Yun Chan <michan@redhat.com>
|