Fix #2779: Wrong error message when wrong multicharacter short opti...#3340
Closed
mattiagaggi wants to merge 1 commit into
Closed
Conversation
… option is passed In _match_short_opt in parser.py, when a character fails to match a short option, check if any registered long option (single-dash multi-char like -dbg) is a prefix of the original argument. If so, raise NoSuchOption with the full argument string instead of just the single unmatched character. This correctly reports 'No such option: -dbgwrong' (or the matched prefix) instead of 'No such option: -d'.
Collaborator
|
AI slop |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Fix the error message when an invalid multi-character single-dash option is passed. Previously,
-dbgwrongwould reportNo such option: -dbecause the parser tried to match each character individually as a short option. Now it correctly reportsNo such option: -dbgwrong.Changes
_match_short_optinparser.py, when a character fails to match a short option, check if any registered single-dash long option (e.g.-dbg) is a prefix of the original argument. If so, raiseNoSuchOptionwith the full argument string instead of just the single unmatched character.-dbg(correct usage) still works and that-dbgwrongproduces an error message referencing the full argument.Testing
pytest tests/test_options.py::test_multicharacter_short_option_wrong_option_errorpassesCloses #2779