Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
Labels
3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
@zzzeek

Description

@zzzeek

Bug report

Bug description:

usingget_annotations() or accessing__annotations__ directly on aTypedDict subclass previously returned a dictionary of all attributes in the TypedDict hierarchy, now only returns for the sub-most class. only happens whenfrom __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__)

CPython versions tested on:

3.14

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp