-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-119180: Use type descriptors to access annotations (PEP 749) #122074
gh-119180: Use type descriptors to access annotations (PEP 749) #122074
Conversation
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.
Looks great!
Returns the __annotate__ function or None. | ||
""" | ||
if isinstance(obj, type): | ||
return _BASE_GET_ANNOTATE(obj) |
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.
It may be worth explaining, in a comment or docstring (here or somewhere) why we have to go to these odd lengths.
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.
Good point, will do that. Thanks for reviewing!
Tests from python/cpython#122074. We don't have to use the base descriptor approach here because we find the annotations directly in the `__dict__` for the class, which avoids metaclass problems.
Tests from python/cpython#122074. We don't have to use the base descriptor approach here because we find the annotations directly in the `__dict__` for the class, which avoids metaclass problems.
A third alternative to #120719 and #120816. See python/peps#3847 (comment).
This PR is on top of #119891.
📚 Documentation preview 📚: https://cpython-previews--122074.org.readthedocs.build/