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

3.14 changes annotations behaviour for dataclasses.make_dataclass #134370

Open
Labels
3.14bugs and security fixesstdlibPython modules in the Lib dirtopic-dataclassestype-bugAn unexpected behavior, bug, or error
@rogerbinns

Description

@rogerbinns

Bug report

Bug description:

I have many dataclasses created on demand by dataclasses.make_dataclass. 3.14 changes behaviour forinstances of the dataclass.

In 3.13 and before, theinstances have a__annotations__ attribute with the expected contents.

In 3.14, that attribute no longer exists, but callinginstance.__annotate_func__ does return what was in__annotations__ before.

The3.14 howto does say "you may access theannotations data member manually"

importdataclassesimportinspectdc=dataclasses.make_dataclass("foo", (("one",int), ("two",str), ("three",complex)))value=dc(1,'hello',3+4j)print(f"{dir(value)=}")try:print(inspect.get_annotations(value))exceptExceptionasexc:print("inspect.get_annotations exception: ",type(exc),exc)ifhasattr(dc,"__annotate_func__"):print(f"{value.__annotate_func__()=}")

For Python 3.13:

dir(value)=['__annotations__', '__class__', '__dataclass_fields__', '__dataclass_params__ ....

For Python 3.14:

dir(value)=['__annotate_func__', '__annotations_cache__',  '__class__', '__dataclass_fields__' ....

In both casesinspect.get_annotations() does give TypeError.

The release notes cover annotations, but nothing about changes to dataclasses instances.

Perhaps the annotations attributes shouldn't be on instances, but they have been. I also see__annotate_func__ on instances of regular objects from Python classes.

CPython versions tested on:

3.14, 3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesstdlibPython modules in the Lib dirtopic-dataclassestype-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