Skip to content

Fix #2779: Wrong error message when wrong multicharacter short opti...#3340

Closed
mattiagaggi wants to merge 1 commit into
pallets:mainfrom
mattiagaggi:fix/issue-2779-wrong-error-message-when-wrong-multicharacter
Closed

Fix #2779: Wrong error message when wrong multicharacter short opti...#3340
mattiagaggi wants to merge 1 commit into
pallets:mainfrom
mattiagaggi:fix/issue-2779-wrong-error-message-when-wrong-multicharacter

Conversation

@mattiagaggi
Copy link
Copy Markdown

Summary

Fix the error message when an invalid multi-character single-dash option is passed. Previously, -dbgwrong would report No such option: -d because the parser tried to match each character individually as a short option. Now it correctly reports No such option: -dbgwrong.

Changes

  • In _match_short_opt in parser.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, raise NoSuchOption with the full argument string instead of just the single unmatched character.
  • Added test verifying that -dbg (correct usage) still works and that -dbgwrong produces an error message referencing the full argument.

Testing

  • pytest tests/test_options.py::test_multicharacter_short_option_wrong_option_error passes
  • Existing option-related tests remain green

Closes #2779

… 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'.
@kdeldycke
Copy link
Copy Markdown
Collaborator

AI slop

@kdeldycke kdeldycke closed this Apr 15, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong error message when wrong multicharacter short option is passed

3 participants