False positive error "incompatible type"
Aperta
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- 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