Commit graph

183 commits

Author SHA1 Message Date
Savannah Ostrowski
0ed56ed88f
GH-64532: Include parent's required optional arguments in subparser usage (#142355) 2025-12-06 18:30:50 +00:00
Serhiy Storchaka
70c27ce94b
gh-142332: Fix usage formatting for positional arguments in mutually exclusive groups in argparse (GH-142333) 2025-12-06 18:03:45 +00:00
Savannah Ostrowski
5be3405e4e
GH-75949: Fix argparse dropping '|' in mutually exclusive groups on line wrap (#142312) 2025-12-06 15:12:21 +00:00
Savannah Ostrowski
4085ff7b32
GH-142267: Cache formatter to avoid repeated _set_color calls (#142268) 2025-12-05 16:47:50 +00:00
Savannah Ostrowski
4b14529730
GH-139862: Remove color from HelpFormatter (#142274)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-12-05 16:21:31 +00:00
Hugo van Kemenade
e73fbbacbb
gh-141679: Add colour to defaults in argparse help (#141680)
Co-authored-by: Savannah Ostrowski <savannah@python.org>
2025-11-23 00:26:50 +00:00
Serhiy Storchaka
425fd85ca3
gh-138525: Support single-dash long options and prefix_chars in BooleanOptionalAction (GH-138692)
-nofoo is generated for -foo.
++no-foo is generated for ++foo.
/nofoo is generated for /foo.
2025-11-22 20:54:02 +00:00
Serhiy Storchaka
77cb39e0c7
gh-138697: Fix inferring dest from a single-dash long option in argparse (#138699)
* gh-138697: Fix inferring dest from a single-dash long option in argparse

If a short option and a single-dash long option are passed to add_argument(),
dest is now inferred from the single-dash long option.

* Make double-dash options taking priority over single-dash long options.

---------

Co-authored-by: Savannah Ostrowski <savannah@python.org>
2025-11-20 18:41:58 +00:00
Savannah Ostrowski
40096da95a
GH-139946: Colorize error and warning messages in argparse (#140695)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-11-04 16:31:35 +00:00
Jakob
d2f3cfd384
gh-140448: Default suggest_on_error to True in argparse.ArgumentParser (#140450) 2025-10-22 16:15:26 +00:00
Savannah Ostrowski
9fc4366f09
GH-139809: Fix argparse subcommand prog not respecting color environment variables (#139818) 2025-10-09 16:53:14 +00:00
ed
72e370c910
gh-139736: Fix argparse indentation overshoot (#139738)
Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
2025-10-08 15:36:53 +00:00
Hugo van Kemenade
872eafd2b0
gh-76007: Deprecate __version__ attribute (#138675)
Co-authored-by: AN Long <aisk@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-09-29 12:03:23 +03:00
Pablo Galindo Salgado
acbe896cb1
GH-130645: Default to color help in argparse (#136809)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2025-07-20 14:55:44 -07:00
Michał Górny
965c480566
gh-134970: Fix exception message in argparse module (GH-134971)
Fix the "unknown action" exception in argparse.ArgumentParser.add_argument_group()
to correctly replace the action class.
2025-06-01 08:56:56 +03:00
Serhiy Storchaka
71cf4dd622
gh-134109: Fix showing comments in pydoc output for argparse (GH-134110)
Comments immediately preceding the object's source code are used
if the object has no docstring.
Comments that do not describe the object should be separated from
the following source code by an empty line.
2025-05-16 23:29:14 +03:00
Serhiy Storchaka
734e15b70d
gh-133653: Fix argparse.ArgumentParser with the formatter_class argument (GH-133813)
* Fix TypeError when formatter_class is a custom subclass of
  HelpFormatter.
* Fix TypeError when formatter_class is not a subclass of
  HelpFormatter and non-standard prefix_char is used.
* Fix support of colorizing when formatter_class is not a subclass of
  HelpFormatter.
* Remove the prefix_chars parameter of HelpFormatter.
2025-05-12 20:27:34 +03:00
Łukasz Langa
f610bbdf74
gh-133346: Make theming support in _colorize extensible (GH-133347)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-05-05 23:45:25 +02:00
Hugo van Kemenade
e6c518d2eb
gh-133300: argparse: make suggest_on_error a keyword-only parameter (#133302) 2025-05-02 18:11:44 +03:00
Hugo van Kemenade
4701ff92d7
gh-130645: Add color to argparse help (GH-132323) 2025-05-02 15:06:10 +02:00
Savannah Ostrowski
2104bde572
GH-127133: Remove ability to nest argument groups & mutually exclusive groups (#127186) 2024-11-24 15:20:37 +00:00
Serhiy Storchaka
0cb4d6c654
gh-86463: Fix default prog in subparsers if usage is used in the main parser (GH-125891)
The usage parameter of argparse.ArgumentParser no longer
affects the default value of the prog parameter in subparsers.

Previously the full custom usage of the main parser was used as
the prog prefix in subparsers.
2024-11-22 17:29:33 +02:00
Serhiy Storchaka
79805d2284
gh-117941: Reject option names starting with "--no-" in argparse.BooleanOptionalAction (GH-125894)
They never worked correctly.
2024-11-11 18:28:30 +02:00
Serhiy Storchaka
cc9a183993
gh-126068: Fix exceptions in the argparse module (GH-126069)
* Only error messages for ArgumentError and ArgumentTypeError are now
  translated.
* ArgumentError is now only used for command line errors, not for logical
  errors in the program.
* TypeError is now raised instead of ValueError for some logical errors.
2024-10-30 18:14:27 +02:00
Serhiy Storchaka
834ba5aaf2
gh-58032: Deprecate the argparse.FileType type converter (GH-124664) 2024-10-23 10:50:29 +03:00
Serhiy Storchaka
759a54d28f
gh-125355: Rewrite parse_intermixed_args() in argparse (GH-125356)
* The parser no longer changes temporarily during parsing.
* Default values are not processed twice.
* Required mutually exclusive groups containing positional arguments are
  now supported.
* The missing arguments report now includes the names of all required
  optional and positional arguments.
* Unknown options can be intermixed with positional arguments in
  parse_known_intermixed_args().
2024-10-22 10:57:25 +00:00
Savannah Ostrowski
7b04496e5c
gh-125542: Deprecate prefix_chars in ArgumentParser.add_argument_group() (GH-125563) 2024-10-17 09:11:47 +00:00
Savannah Ostrowski
624be8699a
GH-99749: Add optional feature to suggest correct names (ArgumentParser) (GH-124456) 2024-10-17 10:07:37 +03:00
rindeal
66b3922b97
gh-86357: argparse: use str() consistently and explicitly to print choices (GH-117766)
Signed-off-by: Jan Chren ~rindeal <dev.rindeal@gmail.com>
2024-10-14 09:36:53 +03:00
Serhiy Storchaka
9944ad388c
gh-85935: Check for nargs=0 for positional arguments in argparse (GH-124839)
Raise ValueError in add_argument() if either explicit nargs=0 or action
that does not consume arguments (like 'store_const' or 'store_true') is
specified for positional argument.
2024-10-12 16:04:17 +03:00
Serhiy Storchaka
63cf4e914f
gh-125254: Fix error report about ambiguous option in argparse (GH-125273)
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.
2024-10-12 12:15:37 +00:00
Serhiy Storchaka
a6c0c64de0
gh-59330: Improve error message for dest= for positionals (GH-125215)
Also improve the documentation. Specify how dest and metavar are derived
from add_argument() positional arguments.

Co-authored-by: Simon Law <sfllaw@sfllaw.ca>
2024-10-12 14:46:28 +03:00
Serhiy Storchaka
eb2d268ac7
gh-65865: Raise early errors for invalid help strings in argparse (GH-124899) 2024-10-12 13:10:50 +03:00
Serhiy Storchaka
18c7449768
gh-61011: Fix inheritance of nested mutually exclusive groups in argparse (GH-125210)
Previously, all nested mutually exclusive groups lost their connection
to the group containing them and were displayed as belonging directly
to the parser.

Co-authored-by: Danica J. Sutherland <djsutherland@users.noreply.github.com>
2024-10-11 11:43:29 +03:00
Savannah Ostrowski
0c5a48c1c9
GH-124693: Support parsing negative scientific and complex numbers argparse (GH-124823)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-10-09 21:56:50 +00:00
Serhiy Storchaka
9b31a2d83f
gh-58282: Fix support of tuple metavar for positional arguments in argparse (GH-124782)
Previously, formatting help output or error message for positional argument
with a tuple metavar raised exception.

Co-authored-by: Cyker Way <cykerway@gmail.com>
2024-10-02 11:28:02 +03:00
Serhiy Storchaka
04bfea2d26
gh-66436: Improved prog default value for argparse.ArgumentParser (GH-124799)
It can now have one of three forms:

* basename(argv0) -- for simple scripts
* python arv0 -- for directories, ZIP files, etc
* python -m module -- for imported modules

Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
2024-10-01 22:51:40 +03:00
Serhiy Storchaka
3f27153e07
gh-58573: Fix conflicts between abbreviated long options in the parent parser and subparsers in argparse (GH-124631)
Check for ambiguous options if the option is consumed, not when it is
parsed.
2024-09-29 12:01:03 +03:00
Serhiy Storchaka
95e92ef6c7
gh-116850: Fix argparse for namespaces with not directly writable dict (GH-124667)
It now always uses setattr() instead of setting the dict item to modify
the namespace. This allows to use a class as a namespace.
2024-09-29 11:01:10 +03:00
Serhiy Storchaka
f1a2417b9e
gh-61181: Fix support of choices with string value in argparse (GH-124578)
Substrings of the specified string no longer considered valid values.
2024-09-29 10:57:21 +03:00
Serhiy Storchaka
dac4ec5286
gh-53834: Fix support of arguments with choices in argparse (GH-124495)
Positional arguments with nargs equal to '?' or '*' no longer check
default against choices.
Optional arguments with nargs equal to '?' no longer check const
against choices.
2024-09-29 10:52:52 +03:00
Serhiy Storchaka
61180446ee
gh-124345: Support abbreviated single-dash long options with = in argparse (GH-124428) 2024-09-29 10:52:07 +03:00
Serhiy Storchaka
9bcadf589a
gh-80259: Fix conflict between type and default=SUPPRESS in argparse (GH-124519)
type() no longer called for SUPPRESS.

This only affects positional arguments with nargs='?'.
2024-09-29 10:47:06 +03:00
Serhiy Storchaka
49e105f948
gh-104860: Fix allow_abbrev=False for single-dash long options (GH-124340) 2024-09-29 10:44:34 +03:00
Jérémie Detrey
d3c76dff44
bpo-44864: Do not translate user-provided strings in ArgumentParser.add_subparsers() (GH-27667)
Call _() on literal strings only.
2024-09-24 19:54:50 +00:00
Payton
d21b0b5d36
gh-113008: Correct argparse usage output for required, mutually exclusive groups (GH-113085) 2024-09-24 17:14:35 +03:00
Serhiy Storchaka
4a5e4aade4
gh-59317: Improve parsing optional positional arguments in argparse (GH-124303)
Fix parsing positional argument with nargs equal to '?' or '*' if it is
preceded by an option and another positional argument.
2024-09-24 15:46:41 +03:00
Serhiy Storchaka
3c83f9958c
gh-72795: Make positional arguments with nargs='*' or REMAINDER non-required (GH-124306)
This allows to use positional argument with nargs='*' and without default
in mutually exclusive group and improves error message about required
arguments.
2024-09-24 07:55:33 +00:00
Serhiy Storchaka
c578271366
gh-53780: Ignore the first "--" (double dash) between an option and command in argparse (GH-124275) 2024-09-24 07:35:28 +00:00
Serhiy Storchaka
3094cd17b0
gh-63143: Fix parsing mutually exclusive arguments in argparse (GH-124307)
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".
2024-09-24 10:23:07 +03:00