python / python/mypy

False positive error "incompatible type"

Aperta
#13,566 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-inheritance
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

For this code:

from typing import Any, Generic, TypeVar

T = TypeVar('T')


class EtcdValueWatcherTyped(Generic[T]):
    def __init__(self):
        pass


class EtcdValueWatcher(EtcdValueWatcherTyped[dict[str, Any]]):
    pass


class SettingsWatcher(EtcdValueWatcher):
    def __init__(self, arg1: str):
        self.__arg1 = arg1
        EtcdValueWatcher.__init__(self)


def main():
    watcher = SettingsWatcher('/v1/qwe')

mypy outputs error:

test.py: note: In member "__init__" of class "SettingsWatcher":
test.py:19: error: Argument 1 to "__init__" has incompatible type "SettingsWatcher"; expected "EtcdValueWatcherTyped[T]"  [arg-type]
            EtcdValueWatcher.__init__(self)
                                      ^
Found 1 error in 1 file (checked 1 source file)

which is false positive.

  • Mypy version used: mypy 0.971 (compiled: yes)
  • Mypy command-line flags: mypy --config-file ./mypy.ini ./test.py
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
ignore_missing_imports = True
show_error_codes = True
show_error_context = True
pretty = True
no_site_packages = False
  • Python version used: Python 3.10.6
  • Operating system and version: Fedora 35

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 il riproduttore fornito per Python 3.10 con mypy 0.971 e conferma il falso positivo [arg-type] nella chiamata esplicita a EtcdValueWatcher.init. Analizza l'ereditarietà generica e il controllo dei costruttori nel type checker, quindi aggiungi un test di regressione basato su questo esempio. Il lavoro è completato quando la chiamata valida non produce alcun errore di tipo incompatibile.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.