Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Conversation

dmach
Copy link
Contributor

@dmachdmach commentedAug 26, 2022
edited by bedevere-bot
Loading

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.

@bedevere-bot
Copy link

Most changes to Pythonrequire a NEWS entry.

Please add it using theblurb_it web app or theblurb command-line tool.

@ghost
Copy link

ghost commentedAug 26, 2022
edited by ghost
Loading

All commit authors signed the Contributor License Agreement.
CLA signed

…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.
@dmachdmachforce-pushed thefix-argparse-subparser_all_mutually_exclusive_group_members_suppressed branch from0d6958c to616c5feCompareAugust 26, 2022 13:52
@dmachdmach changed the titlegh-96310: Fix a traceback when all options in a mutually exclusive group are suppressedgh-96310: Fix a traceback in argparse when all options in a mutually exclusive group are suppressedAug 26, 2022
hamdanal added a commit to hamdanal/cpython that referenced this pull requestMay 28, 2023
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 issues:-Closespython#62090-Closespython#62549-Closespython#77048-Closespython#82091-Closespython#89743-Closespython#96310-Closespython#98666These PRs become obsolete:-Closespython#15372-Closespython#96311
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM.

@serhiy-storchaka
Copy link
Member

Thank you for your contribution@dmath and sorry for the delay. I resolved the merge conflict and made some simple tweaks.

@serhiy-storchakaserhiy-storchaka merged commit5f7df88 intopython:mainFeb 21, 2024
@miss-islington-app
Copy link

Thanks@dmach for the PR, and@serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestFeb 21, 2024
…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>
@bedevere-app
Copy link

GH-115767 is a backport of this pull request to the3.12 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestFeb 21, 2024
…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>
@bedevere-appbedevere-appbot removed the needs backport to 3.12only security fixes labelFeb 21, 2024
@bedevere-app
Copy link

GH-115768 is a backport of this pull request to the3.11 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.11only security fixes labelFeb 21, 2024
serhiy-storchaka pushed a commit that referenced this pull requestFeb 21, 2024
…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>
serhiy-storchaka pushed a commit that referenced this pull requestFeb 21, 2024
…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>
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull requestMar 4, 2024
…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.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull requestApr 17, 2024
…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.
encukou pushed a commit that referenced this pull requestMay 7, 2024
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
SonicField pushed a commit to SonicField/cpython that referenced this pull requestMay 8, 2024
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
LukasWoodtli pushed a commit to LukasWoodtli/cpython that referenced this pull requestJan 22, 2025
…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.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@dmach@bedevere-bot@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp