With a new syntax generic function, `T` cannot be used to set a default value to a parameter with `cast()` while `T` can be used for a parameter and return type
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
*Memo:
mypy --strict test.py
mypy 1.19.0
Python 3.14.0
Windows 11
With a new syntax generic function, T cannot be used to set a default value to a parameter with cast() while T can be used for a parameter and return type as shown below:
from typing import cast
# ↓ Error
def func[T](x: T = cast(T, 100)) -> T:
return x # ↑ No error # ↑ No error
error: Name "T" is not defined
If I don't use T with cast(), other error occurs as shown below:
# ↓↓↓ Error
def func[T](x: T = 100) -> T:
return x
error: Incompatible default for argument "x" (default has type "int", argument has type "T")
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 con il riproduttore test.py ed eseguilo con mypy --strict usando le versioni indicate, mypy 1.19.0 e Python 3.14.0. Traccia il modo in cui la nuova sintassi delle funzioni generiche gestisce T nell’espressione predefinita passata a cast(). Il lavoro è completato quando l’esempio accetta il valore predefinito basato su cast mantenendo il comportamento esistente dei tipi del parametro e del valore restituito.
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