Dataclasses fields should evaluate their annotations
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
Proposal:
In Python 3.14 (a5), I was surprised that while
import dataclasses
@dataclasses.dataclass
class X:
a: X | None
print(X.__annotations__)
works as expected and prints,
{'a': __main__.X | None}
if one tries to look at the type of the field using the dataclasses.fields interface:
print(dataclasses.fields(X)[0].type)
then this instead results in a ForwardRef
ForwardRef('X | None')
Surely, someone trying to inspect the field would want the value version, consistent with the new default functionality of __annotations__ rather than trying to figure out how to evaluate the ForwardRef precisely.
The current behaviour was introduced in
where the dataclasses fields are constructed by reading the ForwardRef mode of annotationlib.
I believe this would be backwards in that the type value had to exists without from __future__ import annotations and would be a string with it.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、参照されている CPython のコミットと、annotationlib の ForwardRef モードを読み取る dataclasses のフィールド構築を確認します。その動作を annotations 内の評価済みの値と比較し、続いて互換性のある field.type のセマンティクスを判断し、文書化されている後方互換性に関する懸念に照らして提案された変更を検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100