Skip to content

fix: show full argument in error for unknown short option#3236

Closed
thakoreh wants to merge 1 commit intopallets:mainfrom
thakoreh:fix-wrong-multichar-short-option-error
Closed

fix: show full argument in error for unknown short option#3236
thakoreh wants to merge 1 commit intopallets:mainfrom
thakoreh:fix-wrong-multichar-short-option-error

Conversation

@thakoreh
Copy link
Copy Markdown

@thakoreh thakoreh commented Mar 1, 2026

Summary

Fixes #2779

When processing short options character by character, if an unknown option is encountered, the error message now shows the full argument (e.g., -dbgwrong) instead of just the first unknown character (e.g., -d).

Before

$ python script.py -dbgwrong
Error: No such option: -d

After

$ python script.py -dbgwrong
Error: No such option: -dbgwrong

Changes

  • Changed raise NoSuchOption(opt, ctx=self.ctx) to raise NoSuchOption(arg, ctx=self.ctx) in _match_short_opt

This provides more context when the user makes a typo in a multi-character short option.

When processing short options character by character, if an unknown
option is encountered, the error message now shows the full argument
(e.g., '-dbgwrong') instead of just the first unknown character
(e.g., '-w' or '-d').

Fixes pallets#2779
@thakoreh thakoreh closed this Mar 1, 2026
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong error message when wrong multicharacter short option is passed

1 participant