Skip to content

multi-level hierarchies of TypedDict no longer return superclass elements in __annotations__ as of 3.14.0b1 when future annotations enabled #133701

Closed
@zzzeek

Description

@zzzeek

Bug report

Bug description:

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__ import annotations

from typing import TypedDict

import annotationlib

class Base(TypedDict,total=False):
    a: int
    b: int

class Sub(Base,total=False):
    c: float
    d: 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__)

CPython versions tested on:

3.14

Operating systems tested on:

No response

Linked PRs

Activity

added
type-bugAn unexpected behavior, bug, or error
on May 8, 2025
added a commit that references this issue on May 9, 2025

pythongh-133701: Fix incorrect `__annotations__` on TypedDict defined…

JelleZijlstra

JelleZijlstra commented on May 9, 2025

@JelleZijlstra
Member

Thanks, fix in #133772.

added a commit that references this issue on May 14, 2025

gh-133701: Fix incorrect `__annotations__` on TypedDict defined under…

9836503
added a commit that references this issue on May 14, 2025

pythongh-133701: Fix incorrect `__annotations__` on TypedDict defined…

added a commit that references this issue on May 14, 2025

[3.14] gh-133701: Fix incorrect `__annotations__` on TypedDict define…

d6cb8fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesstdlibPython modules in the Lib dirtopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      multi-level hierarchies of TypedDict no longer return superclass elements in __annotations__ as of 3.14.0b1 when future annotations enabled · Issue #133701 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant