Incompatible types in assignment when a with block has inner method
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
mypy reports an Incompatible types in assignment error when the variable name defined is same across "with" blocks and any of the "with" block contain an inner method. I hope this is on the lines of #15605 and a possible variant of #12246.
To Reproduce
Please use the below code:
with open('file1', 'r') as f:
def do_something(x: int, y: int) -> int:
return x + y
do_something(2, 3)
with open('file2', 'rb') as f:
pass
Expected Behavior
Type check passes.
Actual Behavior
I observed the following error:
main.py:7: error: Incompatible types in assignment (expression has type "BufferedReader", variable has type "TextIOWrapper") [assignment]
Your Environment
- Mypy version used: 1.6.1
- Mypy command-line flags: None, just ran
mypy main.py - 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 eseguendo mypy main.py con l'esempio riprodotto di metodo annidato e with ripetuto con variabile, usando come baseline il comportamento segnalato di mypy 1.6.1. Traccia come vengono inferiti i tipi delle assegnazioni attraverso i blocchi with che contengono metodi interni; il lavoro è completato quando l'esempio supera il controllo dei tipi senza l'errore incompatible-assignment e il comportamento è coperto da un test di regressione appropriato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers, tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100