gh-58573: Fix conflicts between abbreviated long options in the parent parser and subparsers in argparse - #124631
Merged
serhiy-storchaka merged 2 commits intoSep 29, 2024
Conversation
… parent parser and subparsers in argparse Check for ambiguous options if the option is consumed, not when it is parsed.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
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>
|
GH-124759 is a backport of this pull request to the 3.12 branch. |
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>
|
GH-124760 is a backport of this pull request to the 3.13 branch. |
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
This was referenced Oct 5, 2024
serhiy-storchaka
added a commit
that referenced
this pull request
Oct 7, 2024
This was referenced Nov 11, 2024
mjcarroll
pushed a commit
to mjcarroll/ros2
that referenced
this pull request
Aug 23, 2026
Windows CI fails to parse its own command line: colcon: error: unrecognized arguments: -DBUILD_TESTING=ON --no-warn-unused-cli -DINSTALL_EXAMPLES=OFF -DSECURITY=ON -DAPPEND_PROJECT_NAME_TO_INCLUDEDIR=ON argparse will not pass option-looking tokens to an nargs='*' option, so colcon overrides argparse's internal _parse_optional() to make '--cmake-args -DFOO=BAR' work at all (bpo-9334). The override detects the "argparse could not classify this" case by comparing against the exact value _parse_optional() returns, and python/cpython#124631 changed that value to a list of tuples. On Python 3.14 the comparison stops matching, so the override silently does nothing, every -D argument is classified as an unknown option, and none of them reach --cmake-args. colcon-core 0.18.2 added the list form to that comparison. The existing <0.18 ceiling excluded every release that carries the fix, which is what turned the 3.14 bump into a build failure. Verified against the exact CI command line on Python 3.14.3: 0.17.1 collects cmake_args=[] and reports the arguments as unrecognized, while 0.18.2 and 0.21.1 both parse them correctly and exit 0. The range resolves to 0.21.1, and the full environment solves for win-64 and linux-64. Do not re-cap this at the next minor version. A tight ceiling on a tooling dependency is what held the fix out of reach here, and the comment above this block already says these are pinned loosely on purpose.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Check for ambiguous options if the option is consumed, not when it is parsed.