Incorrect __post_init__ order when KW_ONLY used
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
from dataclasses import dataclass, InitVar, KW_ONLY
@dataclass
class A:
_: KW_ONLY
x: InitVar[int]
def __post_init__(self, x: int) -> None:
pass
@dataclass
class C(A):
y: InitVar[str]
def __post_init__(self, x: int, y: str) -> None: # Correct order.
super().__post_init__(x)
gives
a.py:19: error: Argument 2 of "__post_init__" is incompatible with supertype "dataclass"; supertype defines the argument type as "str" [override]
def __post_init__(self, x: int, y: str) -> None:
^~~~~~
a.py:19: error: Argument 3 of "__post_init__" is incompatible with supertype "dataclass"; supertype defines the argument type as "int" [override]
def __post_init__(self, x: int, y: str) -> None:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず報告された Python の例を再現し、post_init に関係する 2 つの override エラーを確認します。次に、引数の順序がどこで導出されるのかを特定するために、KW_ONLY と InitVar に対する mypy の dataclass 処理を追跡します。例がそれらのエラーなしで型チェックを通過し、示されている post_init の順序が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100