python / python/mypy

Inconsistent errors with superclass Liskov violations

オープン
#7,336 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug needs discussion priority-1-normal topic-inheritance
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

  • Are you reporting a bug, or opening a feature request?

Bug report

class ParentA:
    def get_description(self, s: str): ...


class ParentB:
    def get_description(self, i: int): ...


# This is a Liskov violation and needs to be ignored.
class ParentViolation(ParentA, ParentB):  # type: ignore
    ...


class ShouldBeIrrelevant:
    ...


# Inheriting from a violating parent, showing no error
class NoViolation(ParentViolation):
    ...


# Inheriting from a violating parent, but an extra class makes a violation appear
class SpuriousViolation(ParentViolation, ShouldBeIrrelevant):
    ...
  • What is the actual behavior/output?

The NoViolation class line has no errors.
The SpuriousViolation class line has an error of:
error: Definition of "get_description" in base class "ParentA" is incompatible with definition in base class "ParentB"

  • What is the behavior/output you expect?

Either they should both error, or neither should. Personally, I would prefer it if neither errored, since the Liskov violation has already been explicitly ignored by the ParentViolation class. However, I also don't have enough context to know whether this is actually the correct solution.

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

mypy 0.720, and verified with mypy 0.730+dev.17a93eac7d1d78e31fc9b347682d86d8d53fe02b

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された Python スニペットを mypy 0.730+dev で実行し、NoViolation クラス行と SpuriousViolation クラス行の診断を比較してください。checker が無視された ParentViolation と継承されたスーパークラス定義をどのように処理するかを追跡してください。両方のケースが一貫して扱われ、2 つの例をカバーする回帰テストがあれば issue は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
compilers, devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。