You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document that accessing __annotations__ through __dict__ no longer works #139140
Does it reproduce for 3.14.0rc3? (I believe that you meant an RC version as your Python is coming from uv which IIRC usea rc2 at least).
I'm just repeating what uv reports 😁
❯ uv run python
Python 3.14.0a4 (main, Jan 14 2025, 23:28:13) [Clang 19.1.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Reading annotations from the __dict__ is no longer supported as a result of the implementation of PEP-649. Use annotationlib.get_annotations instead.
IIUC, all instances of cls.__dict__['__annotations__'] should now be:
It seems that the meaning of existing code is being silently changed. (As is the case here.) At minimum could it be arranged for cls.__dict__['__annotations__'] to emit an error of some kind? For example, directing them to this issue or suggesting the above fix?
You can use inspect.get_annotations on most versions (since 3.10), and typing_extensions.get_annotations on all.
At minimum could it be arranged for cls.dict['annotations'] to emit an error of some kind? For example, directing them to this issue or suggesting the above fix?
changed the title [-]Python 3.14.0a4: dataclasses no longer respects `__annotations__` being set.[/-][+]Document that accessing `__annotations__` through `__dict__` no longer works[/+]on Sep 19, 2025
@JelleZijlstra — I'd be happy to write up the docs clarification you flagged here, if you're not already planning to.
My read: in Doc/howto/annotations.rst, the "earlier versions of Python" note still suggests cls.__dict__.get('__annotations__', None) as a general fallback, but under PEP 649/749 the class __dict__ storage is lazily populated and a private implementation detail on 3.14+, so that pattern isn't reliable there anymore. I'd re-scope that line to Python 3.9 and earlier only, and point 3.10+/3.14+ readers to inspect.get_annotations / annotationlib.get_annotations (the APIs you mentioned upthread).
Does that match what you had in mind? I'll put a PR together for this.
Activity
picnixz commentedon Sep 18, 2025
Does it reproduce for 3.14.0rc3? (I believe that you meant an RC version as your Python is coming from uv which IIRC usea rc2 at least).
Otherwise, cc @JelleZijlstra @ericvsmith
JelleZijlstra commentedon Sep 18, 2025
Reading annotations from the
__dict__is no longer supported as a result of the implementation of PEP-649. Useannotationlib.get_annotationsinstead.patrick-kidger commentedon Sep 18, 2025
Thank you both for your response!
I'm just repeating what
uvreports 😁IIUC, all instances of
cls.__dict__['__annotations__']should now be:?
It seems that the meaning of existing code is being silently changed. (As is the case here.) At minimum could it be arranged for
cls.__dict__['__annotations__']to emit an error of some kind? For example, directing them to this issue or suggesting the above fix?JelleZijlstra commentedon Sep 18, 2025
You can use
inspect.get_annotationson most versions (since 3.10), andtyping_extensions.get_annotationson all.No, there's no plausible way we could emit a warning on dict access to an arbitrary key. However, there is a Ruff rule for this: https://docs.astral.sh/ruff/rules/access-annotations-from-class-dict/
picnixz commentedon Sep 19, 2025
Considering this is the expected behaviour I am going to close this one as "not an issue"
JelleZijlstra commentedon Sep 19, 2025
I think we should document better that raw
__dict__access no longer works reliably.[-]Python 3.14.0a4: dataclasses no longer respects `__annotations__` being set.[/-][+]Document that accessing `__annotations__` through `__dict__` no longer works[/+]Builder106 commentedon Jun 19, 2026
@JelleZijlstra — I'd be happy to write up the docs clarification you flagged here, if you're not already planning to.
My read: in Doc/howto/annotations.rst, the "earlier versions of Python" note still suggests
cls.__dict__.get('__annotations__', None)as a general fallback, but under PEP 649/749 the class__dict__storage is lazily populated and a private implementation detail on 3.14+, so that pattern isn't reliable there anymore. I'd re-scope that line to Python 3.9 and earlier only, and point 3.10+/3.14+ readers toinspect.get_annotations/annotationlib.get_annotations(the APIs you mentioned upthread).Does that match what you had in mind? I'll put a PR together for this.
JelleZijlstra commentedon Jun 19, 2026
Yes that makes sense!
gh-139140: Document that reading __annotations__ via __dict__ is unre… (