Skip to content
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

Merged
merged 140 commits into from
Jul 27, 2024

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Jul 21, 2024

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/

@JelleZijlstra JelleZijlstra marked this pull request as ready for review July 24, 2024 00:18
Copy link
Member

@carljm carljm left a 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)
Copy link
Member

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.

Copy link
Member Author

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!

@JelleZijlstra JelleZijlstra enabled auto-merge (squash) July 27, 2024 16:13
@JelleZijlstra JelleZijlstra merged commit 45614ec into python:main Jul 27, 2024
34 checks passed
@JelleZijlstra JelleZijlstra deleted the pep649-basedescriptor branch July 27, 2024 16:58
JelleZijlstra added a commit to JelleZijlstra/typing_extensions that referenced this pull request Jul 27, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants