-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix __annotations__ being undefined #10969
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
Fix __annotations__ being undefined #10969
Conversation
@JukkaL bump :) |
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.
Ah, there's a problem with test stubs.
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.
lgtm!
This comment has been minimized.
This comment has been minimized.
@AlexWaygood @hauntsaninja Any suggestions on stub test failures? |
Interesting! The >>> import functools
>>> functools.__annotations__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'functools' has no attribute '__annotations__' In Python >= 3.10, the behaviour is different: >>> import functools
>>> getattr(functools, "__annotations__")
{}
>>> hasattr(functools, "__annotations__")
True So I'd probably say, in an ideal world:
But that sounds... complicated :// |
I find https://docs.python.org/3/howto/annotations.html#annotations-howto to be a useful reference. Leaving aside questions of how Line 981 in c7a8162
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Yeah let's just follow other dunders. |
Thanks for getting this over the line! |
Fix annotations being undefined
Closes #10330
Using the variable
__annotations__
currently leads to an error being raised incorrectly by mypy, as shown in the example in issue #10330:print(__annotations__)
This is because mypy can't find the definition of
__annotations__
. This PR adds a definition of__annotations__
to mypy, which means this type of error should not be raised anymore.