Decorator becomes untyped when it accepts an object of the same type as a certain global.
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
A decorator becomes untyped when it accepts an argument for which we have another instance, globally defined and referred to in the same scope.
The comments in the example should make the bug much more clear.
I had no idea how to describe this issue or search for it, so no idea whether it was reported before.
To Reproduce
from typing import Callable
class Something:
pass
def decorator(buffer: Something) -> Callable[[Callable[[], None]], Callable[[], None]]:
return lambda x: x
def main() -> None:
something # Comment out this line and everything is fine.
another_something = Something()
@decorator(another_something)
def func() -> None:
return
something = Something() # Move this above `main` and everything is fine.
Expected Behavior
The code snippet should pass.
Actual Behavior
$ mypy --strict /tmp/test.py
test.py:16: error: Untyped decorator makes function "func" untyped
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.982
- Mypy command-line flags: --strict
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.13
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 lo snippet con mypy --strict e confronta il comportamento quando il something globale viene rimosso o spostato sopra main. Traccia l’inferenza dei tipi del decoratore e il percorso di risoluzione dei nomi coinvolto in questo esempio. Il lavoro è completato quando lo snippet originale supera il controllo strict senza segnalare un decoratore non tipizzato.
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