Skip to content

fix(commands): support Literal typehints in Option and @option - #3494

Closed
SHANNWD wants to merge 2 commits into
Pycord-Development:masterfrom
SHANNWD:fix/option-literal-typehint
Closed

SHANNWD wants to merge 2 commits into
Pycord-Development:masterfrom
SHANNWD:fix/option-literal-typehint

Conversation

@SHANNWD

@SHANNWD SHANNWD commented Dec 1, 2026

Copy link
Copy Markdown

Summary

Supports typing.Literal[...] annotations in Option.__init__ and the @option decorator so parameters annotated with Literal[...] no longer raise TypeError: issubclass() arg 1 must be a class when input_type is omitted.

  • Resolves uniform str, int, or float Literal values (rejecting bool and mixed types, matching SlashCommand._parse_options).
  • Infers input_type and default OptionChoices from the Literal values when choices is omitted.
  • Preserves explicit choices=... passed to @option / Option when provided.
  • Handles Literal[...] | None / Optional[Literal[...]] via existing _strip_none_type.
  • Adds unit tests in tests/test_options.py covering explicit choices, inferred choices, custom OptionChoice overrides, int / optional Literal, and invalid Literal error cases.

Fixes #3091

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting, examples, ...).

AI Usage Disclosure

AI Usage has been disclosed: Antigravity (AI coding assistant) was used to help diagnose the root cause in discord/commands/options.py, draft the fix and unit tests in tests/test_options.py, and run local checks (pytest, black --check, and basedpyright). The diff and test results were reviewed before submission.

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • I have run black to format my changes.
  • I have read the Contributing Guidelines
  • AI Usage has been disclosed.

@SHANNWD
SHANNWD requested review from a team, Lumabots and NeloBlivion December 1, 2026 10:17
@SHANNWD
SHANNWD requested a review from Paillat-dev December 1, 2026 10:17
@SHANNWD
SHANNWD requested a review from a team as a code owner December 1, 2026 10:17
@github-project-automation github-project-automation Bot moved this to Todo in Pycord Dec 1, 2026
@pycord-app

pycord-app Bot commented Dec 1, 2026

Copy link
Copy Markdown

Thanks for opening this pull request!
Please make sure you have read the Contributing Guidelines and Code of Conduct.

This pull request can be checked-out with:

git fetch origin pull/3494/head:pr-3494
git checkout pr-3494

This pull request can be installed with:

pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3494/head

@Soheab

Soheab commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

There is a (kindof) stale refactor happening at #3126

But I also think it may be good to fix this now rather than later.

@Paillat-dev

Copy link
Copy Markdown
Member

This is already being worked on in #3126 (also linked to the issue !).

Furthermore, we are pausing fixes on options-related code before a refactor due to issues with design. Adding additional patches on top does not make the codebase easier to rework.

For the above reason we'd also rather if a human worked on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Passing choices= to an option and typing it as Literal fails

3 participants