diff --git a/crates/ty_python_semantic/resources/mdtest/literal_promotion.md b/crates/ty_python_semantic/resources/mdtest/literal_promotion.md index 03eb45efbe..eb79c44b6c 100644 --- a/crates/ty_python_semantic/resources/mdtest/literal_promotion.md +++ b/crates/ty_python_semantic/resources/mdtest/literal_promotion.md @@ -335,6 +335,9 @@ reveal_type(x19) # revealed: list[Literal[1]] x20: list[Literal[1]] | None = [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]] + +x22: X[Literal[1]] | None = x(1) +reveal_type(x22) # revealed: X[Literal[1]] ``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 5447ec84a6..faf1a1f491 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -3504,9 +3504,10 @@ impl<'db> Type<'db> { return; }; - let tcx_specialization = tcx - .annotation - .and_then(|tcx| tcx.specialization_of(db, class_literal)); + let tcx_specialization = tcx.annotation.and_then(|tcx| { + tcx.filter_union(db, |ty| ty.specialization_of(db, class_literal).is_some()) + .specialization_of(db, class_literal) + }); for (typevar, ty) in specialization .generic_context(db)