Skip to content

assigning to __annotations__ has no effect in 3.14.0b1 under from __future__ import annotations #133778

@zzzeek

Description

@zzzeek

Bug report

Bug description:

from __future__ import annotations import annotationlib class A: a: int A.__annotations__ = {"a": str} print(A.__annotations__) print(annotationlib.get_annotations(A))

this works in 3.14.0a7, has no effect in 3.14.0b1. there seems to be a new attribute __annotations_cache__ that the assignment goes into but it isn't returned from __annotations__:

# 3.14.0a7 $ ~/.venv314a7/bin/python test4.py {'a': <class 'str'>} {'a': <class 'str'>} # 3.14.0b1 $ ~/.venv314/bin/python test4.py {'a': 'int'} {'a': 'int'} 

If there's a way to get annotationlib.get_annotations() to pick up the change I can use that as a workaround

cc @JelleZijlstra

CPython versions tested on:

3.14

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

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