@overload declarations in stubs - required to be directly adjacent?
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
Currently, mypy requires @overload declarations in stubs to be directly adjacent, with no declarations (e.g. type vars) in between. However, I don't find that requirement in PEP 484 [1], nor in the typing module documentation [2].
[1] https://www.python.org/dev/peps/pep-0484/#function-method-overloading
[2] https://docs.python.org/3/library/typing.html#typing.overload
To Reproduce
Consider the following type stub:
import typing
@typing.overload
def foo() -> None: ...
K = typing.TypeVar('K')
@typing.overload
def foo(k: K) -> K: ...
Then run stubtest on it.
Expected Behavior
According to the documentation, I would expect this stub to be valid.
Actual Behavior
$ python -m mypy.stubtest teststub
error: failed mypy build.
teststub.pyi:4: error: Single overload definition, multiple required
teststub.pyi:8: error: Name 'foo' already defined on line 4
teststub.pyi:8: error: Single overload definition, multiple required
Pulling the type var declaration up fixes it:
import typing
K = typing.TypeVar('K')
@typing.overload
def foo() -> None: ...
@typing.overload
def foo(k: K) -> K: ...
Your Environment
Python 3.7.1 (anaconda) on Linux, latest master of mypy.
I also tested with mypy 0.790 on Windows, with the same result.
$ python --version
Python 3.7.1
$ python -m mypy --version
mypy 0.820+dev.497556f466dcda90d850b23e86c55ec4082be3f5
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 riproducendo il malfunzionamento con il teststub mostrato e python -m mypy.stubtest teststub. Traccia come mypy convalida le dichiarazioni @typing.overload adiacenti e aggiungi un test di regressione che copra il TypeVar interposto; il lavoro è completo quando lo stub viene accettato e le diagnosi di overload esistenti rimangono corrette.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100