Python 3.14: Call __annotate__ on type objects to get annotations#810
Python 3.14: Call __annotate__ on type objects to get annotations#810hroncok wants to merge 1 commit intojcrist:mainfrom
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. |
| 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.
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! |
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.
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.
Fixes #795