-
-
Notifications
You must be signed in to change notification settings - Fork 481
fix(commands): Option not working with str / ForwardRef annotations #2919
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
base: master
Are you sure you want to change the base?
Conversation
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/2919/head:pr-2919
git checkout pr-2919 This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/2919/head |
404889a
to
694de67
Compare
Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR changes out-of-scope parts and removes certain things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where the Option class in Discord commands did not correctly resolve type annotations when they were provided as string literals or forward references (e.g., param: 'ForwardRefToSomeThing'
or when using from __future__ import annotations
).
- Adds support for resolving string-based type annotations using a new
resolve_annotation
utility - Improves parameter validation by adding proper type hints and using iterators more efficiently
- Updates import statements to include necessary utilities and remove unused imports
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
discord/commands/core.py | Adds string annotation resolution logic, improves type hints, and cleans up imports |
CHANGELOG.md | Documents the bug fix for string/forward reference annotation parsing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
||
final_options = [] | ||
for p_name, p_obj in params: | ||
cache = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache is created fresh for each call to _parse_options
, which means annotation resolution results won't be cached across different command parsing operations. Consider moving the cache to a higher scope (instance or class level) to improve performance for repeated annotation resolutions.
Copilot uses AI. Check for mistakes.
Summary
Option did not correctly resolve the type of an annotation when it was typed like
param: 'ForwardRefToSomeThing'
or when usingfrom __future__ import annotations
.Information
examples, ...).
Checklist
type: ignore
comments were used, a comment is also left explaining why.