Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
gh-96310: Fix a traceback in argparse when all options in a mutually exclusive group are suppressed#96311
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
bedevere-bot commentedAug 26, 2022
Most changes to Pythonrequire a NEWS entry. Please add it using theblurb_it web app or theblurb command-line tool. |
ghost commentedAug 26, 2022 • edited by ghost
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by ghost
Uh oh!
There was an error while loading.Please reload this page.
…ually exclusive group are suppressedReproducer depends on terminal size - the traceback occurs when there'san 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 insertsfixes the problem.
0d6958c
to616c5fe
CompareRationale=========argparse performs a complex formatting of the usage for argument groupingand for line wrapping to fit the terminal width. This formatting has beena constant source of bugs for at least 10 years (see linked issues below)where defensive assertion errors are triggered or brackets and paranthesisare not properly handeled.Problem=======The current implementation of argparse usage formatting relies on regularexpressions to group arguments usage only to separate them again laterwith another set of regular expressions. This is a complex and error proneapproach that caused all the issues linked below. Special casing certainargument formats has not solved the problem. The following are some ofthe most common issues:- empty `metavar`- mutually exclusive groups with `SUPPRESS`ed arguments- metavars with whitespace- metavars with brackets or paranthesisSolution========The following two comments summarize the solution:-python#82091 (comment)-python#77048 (comment)Mainly, the solution is to rewrite the usage formatting to avoid thegroup-then-separate approach. Instead, the usage parts are kept separateand only joined together at the end. This allows for a much simplerimplementation that is easier to understand and maintain. It avoids theregular expressions approach and fixes the corresponding issues.This closes the following issues:-Closespython#62090-Closespython#62549-Closespython#77048-Closespython#82091-Closespython#89743-Closespython#96310-Closespython#98666These PRs become obsolete:-Closespython#15372-Closespython#96311
…e_group_members_suppressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM.
Thank you for your contribution@dmath and sorry for the delay. I resolved the merge conflict and made some simple tweaks. |
Thanks@dmach for the PR, and@serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
…ually exclusive group are suppressed (pythonGH-96311)Reproducer depends on terminal size - the traceback occurs when there'san 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 insertsfixes the problem.(cherry picked from commit5f7df88)Co-authored-by: Daniel Mach <daniel.mach@suse.com>
GH-115767 is a backport of this pull request to the3.12 branch. |
…ually exclusive group are suppressed (pythonGH-96311)Reproducer depends on terminal size - the traceback occurs when there'san 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 insertsfixes the problem.(cherry picked from commit5f7df88)Co-authored-by: Daniel Mach <daniel.mach@suse.com>
GH-115768 is a backport of this pull request to the3.11 branch. |
…tually exclusive group are suppressed (GH-96311) (GH-115768)Reproducer depends on terminal size - the traceback occurs when there'san 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 insertsfixes the problem.(cherry picked from commit5f7df88)Co-authored-by: Daniel Mach <daniel.mach@suse.com>
…tually exclusive group are suppressed (GH-96311) (GH-115767)Reproducer depends on terminal size - the traceback occurs when there'san 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 insertsfixes the problem.(cherry picked from commit5f7df88)Co-authored-by: Daniel Mach <daniel.mach@suse.com>
…ually exclusive group are suppressed (pythonGH-96311)Reproducer depends on terminal size - the traceback occurs when there'san 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 insertsfixes the problem.
…ually exclusive group are suppressed (pythonGH-96311)Reproducer depends on terminal size - the traceback occurs when there'san 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 insertsfixes the problem.
Rationale=========argparse performs a complex formatting of the usage for argument groupingand for line wrapping to fit the terminal width. This formatting has beena constant source of bugs for at least 10 years (see linked issues below)where defensive assertion errors are triggered or brackets and paranthesisare not properly handeled.Problem=======The current implementation of argparse usage formatting relies on regularexpressions to group arguments usage only to separate them again laterwith another set of regular expressions. This is a complex and error proneapproach that caused all the issues linked below. Special casing certainargument formats has not solved the problem. The following are some ofthe most common issues:- empty `metavar`- mutually exclusive groups with `SUPPRESS`ed arguments- metavars with whitespace- metavars with brackets or paranthesisSolution========The following two comments summarize the solution:-#82091 (comment)-#77048 (comment)Mainly, the solution is to rewrite the usage formatting to avoid thegroup-then-separate approach. Instead, the usage parts are kept separateand only joined together at the end. This allows for a much simplerimplementation that is easier to understand and maintain. It avoids theregular expressions approach and fixes the corresponding issues.This closes the following GitHub issues:-#62090-#62549-#77048-#82091-#89743-#96310-#98666These PRs become obsolete:-#15372-#96311
Rationale=========argparse performs a complex formatting of the usage for argument groupingand for line wrapping to fit the terminal width. This formatting has beena constant source of bugs for at least 10 years (see linked issues below)where defensive assertion errors are triggered or brackets and paranthesisare not properly handeled.Problem=======The current implementation of argparse usage formatting relies on regularexpressions to group arguments usage only to separate them again laterwith another set of regular expressions. This is a complex and error proneapproach that caused all the issues linked below. Special casing certainargument formats has not solved the problem. The following are some ofthe most common issues:- empty `metavar`- mutually exclusive groups with `SUPPRESS`ed arguments- metavars with whitespace- metavars with brackets or paranthesisSolution========The following two comments summarize the solution:-python#82091 (comment)-python#77048 (comment)Mainly, the solution is to rewrite the usage formatting to avoid thegroup-then-separate approach. Instead, the usage parts are kept separateand only joined together at the end. This allows for a much simplerimplementation that is easier to understand and maintain. It avoids theregular expressions approach and fixes the corresponding issues.This closes the following GitHub issues:-python#62090-python#62549-python#77048-python#82091-python#89743-python#96310-python#98666These PRs become obsolete:-python#15372-python#96311
…ually exclusive group are suppressed (pythonGH-96311)Reproducer depends on terminal size - the traceback occurs when there'san 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 insertsfixes the problem.
Uh oh!
There was an error while loading.Please reload this page.
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.