This was a regression introduced in gh-58573. It was only tested for the
case when the ambiguous option is the last argument in the command line.
(cherry picked from commit 63cf4e914f)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Previously, all nested mutually exclusive groups lost their connection
to the group containing them and were displayed as belonging directly
to the parser.
(cherry picked from commit 18c7449768)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Danica J. Sutherland <djsutherland@users.noreply.github.com>
Previously, formatting help output or error message for positional argument
with a tuple metavar raised exception.
(cherry picked from commit 9b31a2d83f)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Cyker Way <cykerway@gmail.com>
Check for ambiguous options if the option is consumed, not when it is
parsed.
(cherry picked from commit 3f27153e07)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
It now always uses setattr() instead of setting the dict item to modify
the namespace. This allows to use a class as a namespace.
(cherry picked from commit 95e92ef6c7)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Substrings of the specified string no longer considered valid values.
(cherry picked from commit f1a2417b9e)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
type() no longer called for SUPPRESS.
This only affects positional arguments with nargs='?'.
(cherry picked from commit 9bcadf589a)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Fix parsing positional argument with nargs equal to '?' or '*' if it is
preceded by an option and another positional argument.
(cherry picked from commit 4a5e4aade4)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This allows to use positional argument with nargs='*' and without default
in mutually exclusive group and improves error message about required
arguments.
(cherry picked from commit 3c83f9958c)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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".
(cherry picked from commit 3094cd17b0)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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.
(cherry picked from commit 7ee9921734)
Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
Co-authored-by: Pavel Ditenbir <pavel.ditenbir@gmail.com>
Only the first one has now been removed, all subsequent ones are now
taken literally.
(cherry picked from commit aae126748f)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* 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.
(cherry picked from commit 81a654a342)
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.
(cherry picked from commit 5f7df88821)
Co-authored-by: Daniel Mach <daniel.mach@suse.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
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
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.