Mypy Gives `Incompatible Definitions` Error When Dynamically Typed
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
Discussed in https://github.com/python/typing/discussions/1235
Originally posted by adam-grant-hendry August 4, 2022
Related to this SO question, I'm trying to understand why
but
I would have assumed since nothing is statically typed, that mypy would not produced any errors. In fact, the same code on the pyright playground shows no errors.
I though perhaps the error could be due to the potential for a keyword collision, which I gleaned from PEP 692. e.g. If I made the name of the 4th arguments the same, each could fail the same way if I tried to pass foo as a keyword argument:
>>> a = Foo()
>>> a.run(1, 2, 'baz', foo='bar')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: func() got multiple values for argument 'foo'
but if I keep the argument names different, then the above would work if I tried to call Bar.run(1, 2, 'baz', foo='bar'), but break for Foo.
However, I still would originally assume mypy would do nothing because nothing has been statically typed:
By default, mypy will not type check dynamically typed functions. This means that with a few exceptions, mypy will not report any errors with regular unannotated Python.
To Reproduce
Please see the mypy playground (and pyright playground) gists above.
Expected Behavior
mypy issues no errors.
Actual Behavior
mypy issues the error:
Definition of "run" in base class "Foo" is incompatible with definition in base class "Bar"
Your Environment
- Mypy version used:
mypy 0.971 (compiled: yes) - Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used:
3.8.10, x64-bit - Operating system and version:
Windows 10, version 20H2
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
Inizia con le due riproduzioni mypy-play collegate e confronta il loro comportamento con il Pyright playground collegato, concentrandoti sulle definizioni dei metodi tipizzate dinamicamente e sui **kwargs aggiunti. Controlla la discussione correlata sul typing e i test mypy esistenti per la compatibilità delle definizioni dei metodi; il lavoro è completo quando il comportamento è spiegato e, se viene confermato come un bug, è coperto da un test di regressione.
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à
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100