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: PEP 649: Add __annotate__ attributes #119209

Merged
merged 11 commits into from
May 22, 2024

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented May 20, 2024

This implements https://peps.python.org/pep-0649/#annotate-and-annotations. In separate PRs I will work on making the compiler synthesize __annotate__ functions.

@JelleZijlstra JelleZijlstra changed the title PEP 649: Add __annotate__ attributes gh-119180: PEP 649: Add __annotate__ attributes May 20, 2024
@bedevere-app bedevere-app bot mentioned this pull request May 20, 2024
29 tasks
@JelleZijlstra JelleZijlstra requested a review from ambv May 20, 2024 15:41
@AlexWaygood AlexWaygood removed their request for review May 20, 2024 21:24
Copy link
Contributor

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Some comments. I'm wondering whether the error message "annotate returned a non-dict" could be changed to "annotate must return a dict" or "did not return a dict"

Objects/moduleobject.c Outdated Show resolved Hide resolved
Objects/moduleobject.c Show resolved Hide resolved
Objects/moduleobject.c Outdated Show resolved Hide resolved
@JelleZijlstra
Copy link
Member Author

Some comments. I'm wondering whether the error message "annotate returned a non-dict" could be changed to "annotate must return a dict" or "did not return a dict"

For comparison:

>>> iter(X())
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    iter(X())
    ~~~~^^^^^
TypeError: iter() returned non-iterator of type 'int'

I think I'll make the __annotate__ errors similar.

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 good in general, a few comments.

I would prefer to remove the "set __annotate__ to None" behavior; I guess we would have to ask the Steering Council about that. Maybe not worth it unless we see it causing confusion in practice.

Objects/funcobject.c Outdated Show resolved Hide resolved
Objects/funcobject.c Outdated Show resolved Hide resolved
Objects/typeobject.c Outdated Show resolved Hide resolved
Objects/typeobject.c Outdated Show resolved Hide resolved
@ambv ambv merged commit e9875ec into python:main May 22, 2024
36 checks passed
@JelleZijlstra JelleZijlstra deleted the pep649-anno branch May 22, 2024 06:47
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@JelleZijlstra JelleZijlstra restored the pep649-anno branch September 10, 2024 23:37
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.

4 participants