Skip to content

gh-139140: Document that reading __annotations__ via __dict__ is unre…#151750

Open
Builder106 wants to merge 1 commit into
python:mainfrom
Builder106:gh-139140-annotations-howto
Open

gh-139140: Document that reading __annotations__ via __dict__ is unre…#151750
Builder106 wants to merge 1 commit into
python:mainfrom
Builder106:gh-139140-annotations-howto

Conversation

@Builder106

@Builder106 Builder106 commented Jun 19, 2026

Copy link
Copy Markdown

The "Annotations Best Practices" HOWTO recommended reading a class's annotations via cls.__dict__.get('__annotations__', None) as a general fallback for "earlier versions of Python." Under PEP 649/749 (Python 3.14), annotations are evaluated lazily, and how they're stored in the class __dict__ is a private implementation detail, so that pattern is no longer reliable on 3.14+.

This re-scopes the __dict__ workaround to Python 3.9 and earlier (where neither inspect.get_annotations nor annotationlib.get_annotations is available), and adds a note directing 3.14+ readers to annotationlib.get_annotations / inspect.get_annotations instead.

Docs-only change; no Misc/NEWS.d entry needed.

Fixes #139140

@python-cla-bot

python-cla-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33223222 | 📁 Comparing 80622b7 against main (2e5843e)

  🔍 Preview build  

1 file changed
± howto/annotations.html

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

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Document that accessing __annotations__ through __dict__ no longer works

1 participant