Detect undefined attribute in child class (when defined in parent)
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
mypy does not detect an undefined attribute in a child class if it is defined in a parent class.
Given the following code, where the __init__ of a child class forgets to call super().__init__:
class Base():
def __init__(self, x: int) -> None:
self.x = x
def whatsx(self) -> int:
return self.x
class Child(Base):
def __init__(self, x: int) -> None:
pass
# Note: no call to super(), nor defining self.x.
c = Child(3)
print(c.whatsx()) # mypy does not catch undefined c.x
The real issue is obviously that the child class does not define the x attribute, failing Liskov.
Perhaps this is out-of-scope for mypy, but since programmers make stupid mistakes like this (/me raises hand), it would be awesome if mypy could warn about this error, making said programmers look less stupid ;)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された Base と Child の例に対して mypy を実行し、子クラスの init、継承された x 属性、欠落している super().init の呼び出しに焦点を当てます。mypy が継承された属性とコンストラクターのオーバーライドをどのように処理するかを追跡します。mypy が初期化の欠落を確実に警告し、正しいサブクラスを誤って拒否しなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100