avoid dataclass field regression

This commit is contained in:
Ibraheem Ahmed 2025-12-10 18:33:00 -05:00
parent 5d07d58d59
commit caed80df5e
2 changed files with 11 additions and 6 deletions

View File

@ -37,7 +37,7 @@ class Data:
content: list[int] = field(default_factory=list) content: list[int] = field(default_factory=list)
timestamp: datetime = field(default_factory=datetime.now, init=False) timestamp: datetime = field(default_factory=datetime.now, init=False)
# revealed: (self: Data, content: list[int] = Unknown) -> None # revealed: (self: Data, content: list[int] = list[int]) -> None
reveal_type(Data.__init__) reveal_type(Data.__init__)
data = Data([1, 2, 3]) data = Data([1, 2, 3])

View File

@ -2819,13 +2819,16 @@ impl<'a, 'db> ArgumentTypeChecker<'a, 'db> {
// Prefer the declared type of generic classes. // Prefer the declared type of generic classes.
let preferred_type_mappings = return_with_tcx.and_then(|(return_ty, tcx)| { let preferred_type_mappings = return_with_tcx.and_then(|(return_ty, tcx)| {
let tcx = tcx.filter_union(self.db, |ty| ty.class_specialization(self.db).is_some()); let tcx = tcx.filter_union(self.db, |ty| ty.class_specialization(self.db).is_some());
let return_ty = tcx.class_specialization(self.db)?;
return_ty.filter_union(self.db, |ty| ty.class_specialization(self.db).is_some());
let return_specialization = return_ty
.filter_union(self.db, |ty| ty.class_specialization(self.db).is_some())
.class_specialization(self.db);
// TODO: We should use the constraint solver here to determine the type mappings for more // TODO: We should use the constraint solver here to determine the type mappings for more
// complex subtyping relationships, e.g., `type[C[T]]` to `Callable[..., T]`, or unions // complex subtyping relationships, e.g., callables, protocols, or unions containing multiple
// containing multiple generic elements. // generic elements.
if let Some((class_literal, _)) = return_ty.class_specialization(self.db) if let Some((class_literal, _)) = return_specialization
&& let Some(generic_alias) = class_literal.into_generic_alias() && let Some(generic_alias) = class_literal.into_generic_alias()
{ {
let specialization = generic_alias.specialization(self.db); let specialization = generic_alias.specialization(self.db);
@ -2842,6 +2845,8 @@ impl<'a, 'db> ArgumentTypeChecker<'a, 'db> {
builder.infer(*return_ty, ty).ok()?; builder.infer(*return_ty, ty).ok()?;
} }
} }
} else {
builder.infer(return_ty, tcx).ok()?;
} }
Some(builder.type_mappings().clone()) Some(builder.type_mappings().clone())