Skip to content

fix: handling of Optional[...] in command option type resolution #2852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Lumabots
Copy link
Contributor

@Lumabots Lumabots commented Aug 3, 2025

Summary

This PR fixes an issue where using Optional[T] or T | None as a parameter annotation in command options would raise:

TypeError: Invalid class <class 'NoneType'> used as an input type for an Option

Since providing option=None already marks the option as optional (required=False), including None in the type annotation (e.g., str | None) is unnecessary inside the option type itself. Therefore, the code now removes NoneType from the input type annotation without raising an error, allowing the typing to remain clean and correct.

this is now valid

@bridge.bridge_option(name="guild_id", autocomplete=GuildSetup.guild_autocomplete)
async def banner(self, ctx: LumabotContext, guild_id: str | None = None):

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, ...).

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.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

Paillat-dev
Paillat-dev previously approved these changes Aug 3, 2025
Copy link
Member

@Paillat-dev Paillat-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it works it works but options really are a mess...

@Lulalaby Lulalaby requested a review from a team as a code owner August 6, 2025 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants