@overload is required when using @dispatch
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Start with the synthetic Python example in the issue and reproduce mypy's “'overload' decorator expected” error. Investigate how mypy handles decorators and what support for multipledispatch's @dispatch would require; done means the example type-checks without adding runtime @overload decorators.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is there a way to type-check code that uses @dispatch?
For example, consider the following synthetic example code:
from multipledispatch import dispatch
@dispatch(int)
def foo(x: int) -> None:
print('int')
@dispatch(str)
def foo(x: str) -> None:
print('str')
foo(1) # Prints 'int'.
foo('a') # Prints 'str'.
When I try to type-check this code with mypy, I get error: 'overload' decorator expected, because mypy does not recognize the @dispatch decorator.
Adding @overload before each @dispatch would satisfy mypy. However, it raises a run time error saying You should not call an overloaded function.. This makes sense, as the semantics of @overload are "this is only a signature, the real body is elsewhere.".
It seems what is needed is for mypy to directly recognize @dispatch...?
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Merge medio
- 1g 18h
- PR unite (30g)
- 54
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.
Altre issue di python/mypy
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug topic-configuration topic-error-reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
zostera/django-bootstrap4#894 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
use-agent-os/agent-os#3276 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·