Skip to content

bug: show original choice casing in invalid choice errors - #667

Open
Amadeus-22 wants to merge 1 commit into
QuantConnect:masterfrom
Amadeus-22:bug-588-choice-help-casing
Open

Amadeus-22 wants to merge 1 commit into
QuantConnect:masterfrom
Amadeus-22:bug-588-choice-help-casing

Conversation

@Amadeus-22

Copy link
Copy Markdown

Follow-up to #641 for #588. Closes #588.

  • Since Click 8.2 (Expand Choice token normalization + make generic pallets/click#2796), Choice casefolds choices when case_sensitive=False and builds its display strings from those values. Fix readme.py script: Pydantic v2 and Click 8.2+ compatibility #641 fixed --help by overriding get_metavar in CaseInsensitiveChoice, but the invalid choice error still lists lowercased values, e.g. 'bogus' is not one of 'equity', 'forex', ... for lean data generate --security-type bogus.
  • Override get_invalid_choice_message in CaseInsensitiveChoice so it uses the original casing too, sharing the display logic with get_metavar. Matching is unchanged (still case-insensitive).
  • Add tests for CaseInsensitiveChoice: help output casing, case-insensitive input, and the invalid choice message. They pass with Click 8.5.0 and 8.1.8.

Before:

Error: Invalid value for '--security-type': 'bogus' is not one of 'equity', 'forex', 'cfd', 'future', 'crypto', 'option'.

After:

Error: Invalid value for '--security-type': 'bogus' is not one of 'Equity', 'Forex', 'Cfd', 'Future', 'Crypto', 'Option'.

Since Click 8.2 the invalid choice error lists casefolded values for
case-insensitive choices. Use the original casing, as get_metavar
already does for --help, and add tests for CaseInsensitiveChoice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Case handling for Choice help output (values forced to lowercase)

1 participant