python / python/mypy

Inconsistent errors with superclass Liskov violations

Aperta
#7,336 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug needs discussion priority-1-normal topic-inheritance
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

  • 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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esegui lo snippet Python fornito con mypy 0.730+dev e confronta le diagnosi sulle righe delle classi NoViolation e SpuriousViolation. Traccia il modo in cui il checker gestisce la ParentViolation ignorata e le definizioni ereditate della superclasse; l’issue è completata quando entrambi i casi ricevono un trattamento coerente, con un test di regressione che copra i due esempi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
compilers, devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.