(🐞) Call to function decorated with a `Callable` causes inner function to fail to infer type of variable
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
from typing import Any, Callable, TypeVar, _T as T
def bar() -> None:
def inner() -> None:
it.encode() # error: Cannot determine type of 'it'
breaks()
it = ""
deco: Callable[[T], T]
@deco
def breaks() -> None: ...
It appears that the order of the function declarations affects the result(:trollface:):
from typing import Any, Callable, TypeVar
T = TypeVar("T")
deco: Callable[[T], T]
@deco
def doesnt_break() -> None: ...
def bar() -> None:
def inner() -> None:
it.encode() # no error
doesnt_break()
it = ""
I have determined that this only happens when the deco is a Callable, when it is a function there is no error:
from typing import Any, TypeVar, _T as T
def bar() -> None:
def inner() -> None:
it.encode() # no error
doesnt_break()
it = ""
def deco(fn: T) -> T: ...
@deco
def doesnt_break() -> None: ...
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 eseguendo le due riproduzioni Python dell’issue, oppure usa il playground collegato, e confronta la decorazione basata su Callable con il decorator basato su funzione. Segui il percorso di inferenza dei tipi per la funzione interna annidata e la chiamata al decorator; il lavoro è completato quando il primo esempio viene inferito come str senza introdurre regressioni negli esempi che già passano.
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
- 42/100