python / python/cpython

Document that accessing `__annotations__` through `__dict__` no longer works

Open
#139,140 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.14 3.15 docs stdlib topic-typing
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

The following code crashes on 3.14.0a4 but runs without error on 3.13:

import dataclasses

def my_dataclass(cls):
    try:
        annotations = cls.__dict__["__annotations__"]
    except KeyError:
        cls = dataclasses.dataclass()(cls)
    else:
        new_annotations = dict(annotations)
        for name in annotations.keys():
            if name == "ignore_this_annotation":
                new_annotations.pop(name)
        cls.__annotations__ = new_annotations
        cls = dataclasses.dataclass()(cls)
        cls.__annotations__ = annotations
    return cls

@my_dataclass
class X:
    x: int = 3
    ignore_this_annotation: int

with:

TypeError: non-default argument 'ignore_this_annotation' follows default argument 'x'

Python installed via uv venv --python=3.14.

x-ref https://github.com/patrick-kidger/optimistix/issues/168 https://github.com/patrick-kidger/equinox/issues/1096)

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs
  • gh-151750

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the issue's reproducer and linked PR gh-151750 to understand the intended documentation change. Update the relevant Python documentation to explain that accessing annotations through dict no longer works, and confirm the behavior and version context are accurately covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.