Dataclass field ordering should not be enforced when init=False
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Dataclasses support fields that have default values. All fields with defaults must appear after all fields without default values. Mypy enforces this ordering requirement and emits an error ("Attributes without a default cannot follow attributes with one") if it is violated. Pyright does the same.
By default, dataclasses include a synthesized __init__ method, but this behavior can be overridden by including an init=False argument to the dataclass decorator.
A pyright user recently submitted a bug report indicating that the field order requirement should not be enforced when init=False. I've re-read PEP 557, and it doesn't provide clarity on this point.
Either mypy and pyright are both doing the right thing here or both of them have a bug.
Perhaps someone who was involved in the development of PEP 557, the dataclass implementation, or the mypy dataclass internal plugin could help clarify which behavior is correct?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず PEP 557、dataclass の実装、そして mypy の内部 dataclass プラグインを確認し、その後 pyright issue 1753 で報告された動作と比較してください。dataclass デコレーターで init=False を使用した場合にフィールド順序エラーを適用すべきかどうかを判断し、合意された動作を文書化または実装してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100