New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
argparse sometimes tracebacks when all options in a mutually exclusive group are suppressed #96310
Comments
dmach
added a commit
to dmach/cpython
that referenced
this issue
Aug 26, 2022
…ive group are suppressed 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.
dmach
added a commit
to dmach/cpython
that referenced
this issue
Aug 26, 2022
…ually exclusive group are suppressed 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.
hamdanal
added a commit
to hamdanal/cpython
that referenced
this issue
May 28, 2023
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: - python#82091 (comment) - python#77048 (comment) 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 issues: - Closes python#62090 - Closes python#62549 - Closes python#77048 - Closes python#82091 - Closes python#89743 - Closes python#96310 - Closes python#98666 These PRs become obsolete: - Closes python#15372 - Closes python#96311
serhiy-storchaka
pushed a commit
that referenced
this issue
Feb 21, 2024
…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.
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Feb 21, 2024
…ually exclusive group are suppressed (pythonGH-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. (cherry picked from commit 5f7df88) Co-authored-by: Daniel Mach <daniel.mach@suse.com>
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Feb 21, 2024
…ually exclusive group are suppressed (pythonGH-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. (cherry picked from commit 5f7df88) Co-authored-by: Daniel Mach <daniel.mach@suse.com>
serhiy-storchaka
pushed a commit
that referenced
this issue
Feb 21, 2024
…tually exclusive group are suppressed (GH-96311) (GH-115768) 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 5f7df88) Co-authored-by: Daniel Mach <daniel.mach@suse.com>
serhiy-storchaka
pushed a commit
that referenced
this issue
Feb 21, 2024
…tually exclusive group are suppressed (GH-96311) (GH-115767) 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 5f7df88) Co-authored-by: Daniel Mach <daniel.mach@suse.com>
woodruffw
pushed a commit
to woodruffw-forks/cpython
that referenced
this issue
Mar 4, 2024
…ually exclusive group are suppressed (pythonGH-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.
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
…ually exclusive group are suppressed (pythonGH-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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
When a subparser contains a mutually exclusive group and the all options in the group are suppressed,
it sometimes errors out with a traceback. The crash depends on other options (their ordering and length) and terminal size.
Reproducer:
Please note that setting
COLUMNS
to a high number doesn't trigger the traceback:Your environment
Linked PRs
The text was updated successfully, but these errors were encountered: