spec/conformance: function with TypeVar default and default argument used in context.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 302
- Merge medio
- 23h
- PR unite (30g)
- 8
Descrizione
I want to suggest adding the following test to the conformance test suite:
class Getter[T]:
def get[S=None](self, default: S = None) -> T | S: ... # OK
def test(arg: Getter[str]) -> None:
result: str = arg.get() # type: ignore
- Since the default argument value is assignable to the default type var type,
def getis well-defined arg.get()implicitly usesNoneof typeNoneas the argument. Therefore, we have an implicit constraintS <: Nonewhen.getis called without explicit default.
Therefore, result: str = arg.get() should raise an assignment type error (str | None not assignalbe to str).
Currently, only pyright succeeds on this test, and type checker results diverge.
pyright: no errors (true negative ondef get, true positive onresult) (pyright playground)mypy: false positive ondef get, false negative onresult.ty: false positive ondef get, true positive onresult. (playground)pyrefly: false positive ondef get, false negative onresult(playground)zuban: false postive ondef get, false negative onresult.
Related Issues
- https://github.com/python/mypy/issues/3737 (one of the most upvotes issues on mypy)
- https://github.com/astral-sh/ty/issues/592
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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 individuando la suite di test di conformità di typing e i test esistenti per i valori predefiniti di TypeVar e gli argomenti predefiniti. Aggiungi l'esempio Getter proposto con la definizione prevista e le diagnostiche di assegnazione previste, quindi confronta i risultati tra i type checker elencati in modo che l'aspettativa di conformità sia esplicita.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- testing
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100