fix: implement PEP 563 annotations handling in SlashCommand#3233
Closed
code-wolf-byte wants to merge 2 commits into
Closed
fix: implement PEP 563 annotations handling in SlashCommand#3233code-wolf-byte wants to merge 2 commits into
code-wolf-byte wants to merge 2 commits into
Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/3233/head:pr-3233
git checkout pr-3233This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3233/head |
Member
|
your tests are failing |
Member
|
We do not accept slop PRs. You clearly show no understanding of the broader context, and CI is failing. Furthermore, this is a known issue, which has already been discussed internally, as well as #2919 and #2919. We have no plans on accepting external fixed, feature additions or other changes on the Options related code at this time in order to focus on a better refactor of it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Caution
Feature freeze is active, as described by our Release Schedule.
Summary
Fixes slash command option parsing when
from __future__ import annotations(PEP 563)is active in a user's codebase. Under PEP 563, all annotations are stored as strings at
definition time rather than being evaluated eagerly.
_parse_optionswas readingp_obj.annotationdirectly, so when a user wrote:…pycord received the string
"Option(discord.Member, 'Pick a member')"instead of thereal
Optioninstance. The command registered silently, but crashed with:the first time a user invoked it (
_invokecalledissubclass(op._raw_type, Enum)where_raw_typewas a plain string).This was first reported in #513 (2021). PR #1251 closed that issue by promoting the
param: type = Option(...)default-value pattern as the canonical API — a workaround,not a fix to the underlying annotation parsing.
Changes in this PR:
_parse_optionsand_match_option_param_namesindiscord/commands/core.pynowcall
typing.get_type_hints(self.callback, include_extras=True)instead of readingp_obj.annotationdirectly.get_type_hintsevaluates string annotations back totheir original types regardless of whether PEP 563 is active. A bare
except Exceptionfalls back to the raw annotation if hint resolution fails (e.g. unresolvable forward
references), so the change is backwards-compatible.
isinstance(op._raw_type, type)guard is added before theissubclass(op._raw_type, Enum)call in_invoke, preventing aTypeErrorcrasheven if a string
_raw_typeever slips through from another code path.AI disclosure: Generative AI (Claude, Anthropic) was used to identify and analyze this bug, produce partial code changes, and write the tests. The author has reviewed and understands all changes made.
Information
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.