Local type inference of numeric variables
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
I have a very simple example program that produces surprising and (I think...) wrong behavior:
foo = 0
foo = 1.0
Running mypy against this file yields
test.py:3: error: Incompatible types in assignment (expression has type "float", variable has type "int")
But foo could(/should) be inferred as a float in this environment. I draw this conclusion from PEP-484
when an argument is annotated as having type float, an argument of type int is acceptable
(although this is not about function arguments per se).
I know that some improvements have been recently been made to type inference in 0.770 to use information from second (or subsequent) assignments, rather than just the first assignment. So maybe a widening from int to float could be implemented in the same way...?
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
Riproduci il comportamento con l'esempio test.py usando mypy, quindi esamina le modifiche locali all'inferenza dei tipi indicate per la versione 0.770 e le indicazioni pertinenti di PEP-484. Il lavoro sarà completato quando sarà stabilito se una variabile a cui è stato assegnato un int può successivamente essere ampliata a float e sarà inclusa la copertura del comportamento di assegnazione risultante.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100