Document that accessing `__annotations__` through `__dict__` no longer works
未關閉
還沒有人認領這個 Issue。
3.14
3.15
docs
stdlib
topic-typing
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先檢視 issue 的重現程式和連結的 PR gh-151750,以了解預期的文件變更。更新相關的 Python 文件,說明透過 dict 存取 annotations 已不再有效,並確認其中正確涵蓋了該行為及版本背景。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100