Dataclass constructors defaults don't solve type parameters
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 57/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- developer-experience, testing-qa
Direzione di ricerca
Start by reading the generated dataclass constructor logic and the generic argument solving path in Pyrefly; the issue does not name specific source files or tests. Use the Python example in the issue as a regression case: Generated() should reveal Generated[int], while Generated(5) should continue to reveal Generated[int]. Add or update a focused type-checker test for those results.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the Bug
Consider this code:
from dataclasses import dataclass
from typing import reveal_type
class Explicit[T]:
def __init__(self, x: T = 5) -> None:
self.x = x
@dataclass
class Generated[T]:
x: T = 5 # pyrefly: ignore[bad-assignment]
reveal_type(Explicit()) # Explicit[int]
reveal_type(Generated()) # Generated[@_] — expected Generated[int]
reveal_type(Generated(5)) # Generated[int]
There's a gap in our generated dataclass constructor logic. The default value for x is not actually affecting how calls solve. It's clear from Explicit that we intend for default constructor arguments to solve generic tparams when suitable, but in Generated we ignore the fact that the default of 5 means T ought to solve to int.
Note that it's possible to make this example work with T = int, a tparam-level default. But that's not a good solution - as a rule we don't want to use tparam-level defaults (which are an advanced feature and have some probably-undesirable side effects, like making a bare Generated mean Generated[int] rather than Generated[Any]) for a case where they aren't necessary
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
- Lingua principale
- Rust
- Stelle
- 7.2k
- Fork
- 578
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi 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.
Altre issue di facebook/pyrefly
-
False positive: `Protocol` with `EXCLUDED_ATTRIBUTES` cannot be used with `issubclass()`Forse già presa @amas127 l’ha presa oggi. Apertatypechecking
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 57/100
-
configuration quansight
Difficoltà 3/5 Mezza giornata Idoneità per principianti 55/100
-
Version-gated early exits: `from copy import replace` is accepted but `copy.replace` is rejectedApertaquansight scoping-control-flow
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
Tutte le issue di facebook/pyrefly
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
datafusion-contrib/StreamFusion#653 ·
I maintainer di solito rispondono entro 1 giorno
-
bug CLI exec session
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tursodatabase/turso#11734 ·
I maintainer di solito rispondono entro 1 giorno
-
quality testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
compatibility
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno