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
multi-level hierarchies of TypedDict no longer return superclass elements in __annotations__ as of 3.14.0b1 when future annotations enabled #133701
using get_annotations() or accessing __annotations__ directly on a TypedDict subclass previously returned a dictionary of all attributes in the TypedDict hierarchy, now only returns for the sub-most class. only happens when from __future__ import annotations is used; when not used, then it works as previously. there's no workaround here because the typeddict subclass does not include declared superclasses in its __mro__.
from __future__ importannotationsfromtypingimportTypedDictimportannotationlibclassBase(TypedDict,total=False):
a: intb: intclassSub(Base,total=False):
c: floatd: int# for both, py3.14.0a7 has all four, py3.14.0b1 has only c, d# py3.14.0a7: {'a': ForwardRef('int', module='__main__'), 'b': ForwardRef('int', module='__main__'), 'c': ForwardRef('float', module='__main__'), 'd': ForwardRef('int', module='__main__')}# py3.14.0b1: {'c': 'float', 'd': 'int'}print(Sub.__annotations__)
print(annotationlib.get_annotations(Sub))
# there's no way to traverse the ``__mro__`` of the Sub class to find# these annotations since Base is not there; prints# (<class '__main__.Sub'>, <class 'dict'>, <class 'object'>)print(Sub.__mro__)
Activity
pythongh-133701: Fix incorrect `__annotations__` on TypedDict defined…
JelleZijlstra commentedon May 9, 2025
Thanks, fix in #133772.
gh-133701: Fix incorrect `__annotations__` on TypedDict defined under…
pythongh-133701: Fix incorrect `__annotations__` on TypedDict defined…
[3.14] gh-133701: Fix incorrect `__annotations__` on TypedDict define…
pythongh-133701: Fix incorrect `__annotations__` on TypedDict defined…
pythongh-133701: Fix incorrect `__annotations__` on TypedDict defined…