mirror of https://github.com/astral-sh/ruff
[ty] Narrow type context during literal promotion in generic class constructors (#21574)
## Summary Resolves https://github.com/astral-sh/ty/issues/1603.
This commit is contained in:
parent
09d457aa52
commit
040aa7463b
|
|
@ -335,6 +335,9 @@ reveal_type(x19) # revealed: list[Literal[1]]
|
||||||
x20: list[Literal[1]] | None = [1]
|
x20: list[Literal[1]] | None = [1]
|
||||||
reveal_type(x20) # revealed: list[Literal[1]]
|
reveal_type(x20) # revealed: list[Literal[1]]
|
||||||
|
|
||||||
x21: X[Literal[1]] | None = x(1)
|
x21: X[Literal[1]] | None = X(1)
|
||||||
reveal_type(x21) # revealed: X[Literal[1]]
|
reveal_type(x21) # revealed: X[Literal[1]]
|
||||||
|
|
||||||
|
x22: X[Literal[1]] | None = x(1)
|
||||||
|
reveal_type(x22) # revealed: X[Literal[1]]
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -3504,9 +3504,10 @@ impl<'db> Type<'db> {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let tcx_specialization = tcx
|
let tcx_specialization = tcx.annotation.and_then(|tcx| {
|
||||||
.annotation
|
tcx.filter_union(db, |ty| ty.specialization_of(db, class_literal).is_some())
|
||||||
.and_then(|tcx| tcx.specialization_of(db, class_literal));
|
.specialization_of(db, class_literal)
|
||||||
|
});
|
||||||
|
|
||||||
for (typevar, ty) in specialization
|
for (typevar, ty) in specialization
|
||||||
.generic_context(db)
|
.generic_context(db)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue