python / python/cpython

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

オープン
#139,140 コメント 8 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

3.14 3.15 docs stdlib topic-typing
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、意図されたドキュメント変更を理解するために、issue の再現例とリンクされている PR gh-151750 を確認します。関連する Python ドキュメントを更新して、dict を介して annotations にアクセスすることはもはや機能しないことを説明し、動作とバージョンの文脈が正確に扱われていることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。