Document that accessing `__annotations__` through `__dict__` no longer works
未关闭
还没有人认领这个 Issue。
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先查看 issue 的复现程序和链接的 PR gh-151750,以了解预期的文档变更。更新相关的 Python 文档,说明通过 dict 访问 annotations 已不再有效,并确认其中准确涵盖了该行为及版本背景。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100