-
Notifications
You must be signed in to change notification settings - Fork 103
Python 3.14: Call __annotate__ on type objects to get annotations #810
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
Conversation
This fix works on 3.14.0a6 👍 |
But it doesn't on 3.14.0b1 😅 |
I was thinking that maybe the solution is to reverse the order (aka look into |
@JelleZijlstra sorry for bothering you directly, but do you by chance know how to fix this code? I mostly contributed this by trial and error and it no longer works with 3.14.0b1. Thanks. |
@@ -149,7 +149,12 @@ def get_class_annotations(obj): | |||
cls_locals = dict(vars(cls)) | |||
cls_globals = getattr(sys.modules.get(cls.__module__, None), "__dict__", {}) | |||
|
|||
ann = cls.__dict__.get("__annotations__", {}) |
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 should just use inspect.get_annotations(cls)
which will work on all versions.
You may want to use the FORWARDREF format on 3.14 to support classes with annotations that cannot be fully evaluated. I don't know if that's a design goal for this function.
Retrieving I realize the code where this happens is in C so what I say might not be straightforward though. Would it be OK for the C code to import |
With this change, the tests run for me on a local build of Python 3.14. There are a lot of failures related to sys.getrefcount() but that seems to be an unrelated issue. Closes jcrist#810. Fixes jcrist#651. Fixes jcrist#795.
I proposed an alternative fix: #852. |
Thank you, @JelleZijlstra! |
Fixes #795