Skip to content

docs/fix: clarify shortcut key must be lowercase a–z or digit 0–9#487

Open
ttw225 wants to merge 2 commits intotmbo:masterfrom
ttw225:docs/clarify-shortcut-key-constraints
Open

docs/fix: clarify shortcut key must be lowercase a–z or digit 0–9#487
ttw225 wants to merge 2 commits intotmbo:masterfrom
ttw225:docs/clarify-shortcut-key-constraints

Conversation

@ttw225
Copy link
Copy Markdown

@ttw225 ttw225 commented Mar 11, 2026

Questionary is an awesome work!!
I've been using it comfortably alongside Commitizen and followed the same patterns when building CLI flows.

What is the problem that this PR addresses?

One small pain point is the shortcut key story: when use_shortcuts is on (e.g. select, rawselect), choices can take a dict key (or Choice(..., shortcut_key=...)), but the docs and the thrown error didn’t spell out the real rule clearly.

The allowed set is already defined in code as InquirerControl.SHORTCUT_KEYS—only single digits 0–9 and single lowercase letters a–z. The previous error text said shortcuts “should be single characters or numbers,” which is easy to read as “any single character,” so users can hit a confusing ValueError (e.g. using an uppercase letter) without knowing why.

...

How did you solve it?

  • Docstrings: Updated Choice’s shortcut_key parameter, and the shortcut_key property so they state explicitly that values must be a single lowercase letter (a–z) or digit (0–9), matching SHORTCUT_KEYS.
  • Error message: Replaced the vague wording in _assign_shortcut_keys() with a clear message and fixed the missing space between "Invalid shortcut '…'" and "for choice …".

...

Example (invalid key — uppercase X):

import questionary
questionary.select(
    "Pick one",
    use_shortcuts=True,
    choices=[
        {"name": "Apple", "key": "a"},
        {"name": "Banana", "key": "b"},
        {"name": "Cherry", "key": "X"},
    ],
).ask()

Resulting error text:

ValueError: Invalid shortcut 'X' for choice 'Cherry'.
Shortcuts must be a single lowercase letter (a-z) or digit (0-9), and must be unique.

Original error text:

ValueError: Invalid shortcut 'X'for choice 'Cherry'.
Shortcuts should be single characters or numbers. Make sure that all your shortcuts are unique.

Checklist

  • I have read the Contributor's Guide.
  • I will check that all automated PR checks pass before the PR gets reviewed.

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.

1 participant