Skip to content
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

gh-58573: Fix conflicts between abbreviated long options in the parent parser and subparsers in argparse #124631

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Sep 26, 2024

Check for ambiguous options if the option is consumed, not when it is parsed.

… parent parser and subparsers in argparse

Check for ambiguous options if the option is consumed, not when it is
parsed.
@serhiy-storchaka serhiy-storchaka merged commit 3f27153 into python:main Sep 29, 2024
34 checks passed
@miss-islington-app
Copy link

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the argparse-abbrev-subparser branch September 29, 2024 09:01
@miss-islington-app
Copy link

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 3f27153e077d7e9448e2f081275931968b40cc74 3.13

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 29, 2024
… parent parser and subparsers in argparse (pythonGH-124631)

Check for ambiguous options if the option is consumed, not when it is
parsed.
(cherry picked from commit 3f27153)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Sep 29, 2024

GH-124759 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Sep 29, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Sep 29, 2024
… in the parent parser and subparsers in argparse (pythonGH-124631)

Check for ambiguous options if the option is consumed, not when it is
parsed.
(cherry picked from commit 3f27153)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Sep 29, 2024

GH-124760 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Sep 29, 2024
serhiy-storchaka added a commit that referenced this pull request Sep 29, 2024
…e parent parser and subparsers in argparse (GH-124631) (GH-124759)

Check for ambiguous options if the option is consumed, not when it is
parsed.
(cherry picked from commit 3f27153)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@serhiy-storchaka serhiy-storchaka removed their assignment Sep 29, 2024
AdamWill added a commit to AdamWill/pykickstart that referenced this pull request Oct 2, 2024
In Python 3.13 and 3.12.7, the behavior of _parse_optional has
changed. It used to raise an error on multiple matching actions
itself, and only ever return None or an option tuple. Now the
"raise error on multiple matching actions" code was moved out
into consume_optional, and _parse_optional returns either None
or a *list* of option tuples, which contains more than one if
multiple actions match. See:

python/cpython#124631
python/cpython#58573

This adapts to the change in a way that should work on both older
and newer Pythons. I re-implemented the handling of multiple
matching options so we don't have to worry about licensing and
attribution if we copied in upstream's version.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
AdamWill added a commit to AdamWill/pykickstart that referenced this pull request Oct 2, 2024
In Python 3.13 and 3.12.7, the behavior of _parse_optional has
changed. It used to raise an error on multiple matching actions
itself, and only ever return None or an option tuple. Now the
"raise error on multiple matching actions" code was moved out
into consume_optional, and _parse_optional returns either None
or a *list* of option tuples, which contains more than one if
multiple actions match. See:

python/cpython#124631
python/cpython#58573

This adapts to the change in a way that should work on both older
and newer Pythons.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
AdamWill added a commit to AdamWill/pykickstart that referenced this pull request Oct 2, 2024
In Python 3.13 and 3.12.7, the behavior of _parse_optional has
changed. It used to raise an error on multiple matching actions
itself, and only ever return None or an option tuple. Now the
"raise error on multiple matching actions" code was moved out
into consume_optional, and _parse_optional returns either None
or a *list* of option tuples, which contains more than one if
multiple actions match. See:

python/cpython#124631
python/cpython#58573

This adapts to the change in a way that should work on both older
and newer Pythons.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
bcl pushed a commit to pykickstart/pykickstart that referenced this pull request Oct 2, 2024
In Python 3.13 and 3.12.7, the behavior of _parse_optional has
changed. It used to raise an error on multiple matching actions
itself, and only ever return None or an option tuple. Now the
"raise error on multiple matching actions" code was moved out
into consume_optional, and _parse_optional returns either None
or a *list* of option tuples, which contains more than one if
multiple actions match. See:

python/cpython#124631
python/cpython#58573

This adapts to the change in a way that should work on both older
and newer Pythons.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
bcl pushed a commit to bcl/pykickstart that referenced this pull request Oct 4, 2024
In Python 3.13 and 3.12.7, the behavior of _parse_optional has
changed. It used to raise an error on multiple matching actions
itself, and only ever return None or an option tuple. Now the
"raise error on multiple matching actions" code was moved out
into consume_optional, and _parse_optional returns either None
or a *list* of option tuples, which contains more than one if
multiple actions match. See:

python/cpython#124631
python/cpython#58573

This adapts to the change in a way that should work on both older
and newer Pythons.

NOTE: This includes the fix for the typo that is in a separate commit on
master.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
Signed-off-by: Brian C. Lane <bcl@redhat.com>

Resolves: RHEL-61426
serhiy-storchaka added a commit that referenced this pull request Oct 7, 2024
…e parent parser and subparsers in argparse (GH-124631) (GH-124760)

Check for ambiguous options if the option is consumed, not when it is
parsed.
(cherry picked from commit 3f27153)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant