Skip to content

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

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
SankofaForge:gh-139140-annotations-howto
Nov 1, 2026
Merged

JelleZijlstra merged 1 commit into
python:mainfrom
SankofaForge:gh-139140-annotations-howto

Conversation

@Builder106

@Builder106 Builder106 commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 23, 2026
@Builder106

Copy link
Copy Markdown
Contributor Author

@JelleZijlstra

Could someone review this docs change? It limits the __dict__ workaround to Python 3.9 and earlier and points readers on 3.14+ to the supported annotation APIs. CI is passing, including the docs checks.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Oct 28, 2026
@JelleZijlstra
JelleZijlstra merged commit 410fdda into python:main Nov 1, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Nov 1, 2026
@picnixz picnixz added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 1, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @Builder106 for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @Builder106 for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

GH-161050 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 1, 2026
@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

GH-161051 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 1, 2026
hugovk pushed a commit that referenced this pull request Nov 1, 2026
…is unre… (GH-151750) (#161051)

gh-139140: Document that reading __annotations__ via __dict__ is unre… (GH-151750)
(cherry picked from commit 410fdda)

Co-authored-by: Olayinka Vaughan <114308865+Builder106@users.noreply.github.com>
hugovk pushed a commit that referenced this pull request Nov 1, 2026
…is unre… (GH-151750) (#161050)

gh-139140: Document that reading __annotations__ via __dict__ is unre… (GH-151750)
(cherry picked from commit 410fdda)

Co-authored-by: Olayinka Vaughan <114308865+Builder106@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Document that accessing __annotations__ through __dict__ no longer works

3 participants