diff --git a/crates/ty_python_semantic/resources/mdtest/generics/specialize_constrained.md b/crates/ty_python_semantic/resources/mdtest/generics/specialize_constrained.md index 3f373f99aa..789a58d40f 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/specialize_constrained.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/specialize_constrained.md @@ -43,7 +43,7 @@ def unbounded[T](): reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(Never, T, int) | ConstraintSet.range(Never, T, bool))) # revealed: ty_extensions.Specialization[T@unbounded = int | str] reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(Never, T, int) | ConstraintSet.range(Never, T, str))) - # revealed: ty_extensions.Specialization[T@unbounded = str | bool] + # revealed: ty_extensions.Specialization[T@unbounded = bool | str] reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(bool, T, bool) | ConstraintSet.range(Never, T, str))) ``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index f471c25a33..8dad588bba 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -8217,10 +8217,11 @@ impl<'db> KnownInstanceType<'db> { ) } KnownInstanceType::Specialization(specialization) => { + // Normalize for consistent output across CI platforms write!( f, "ty_extensions.Specialization{}", - specialization.display_full(self.db) + specialization.normalized(self.db).display_full(self.db) ) } KnownInstanceType::UnionType(_) => f.write_str("types.UnionType"), diff --git a/crates/ty_python_semantic/src/types/generics.rs b/crates/ty_python_semantic/src/types/generics.rs index 43bfb6f2d2..2ee21a02ba 100644 --- a/crates/ty_python_semantic/src/types/generics.rs +++ b/crates/ty_python_semantic/src/types/generics.rs @@ -1003,6 +1003,11 @@ impl<'db> Specialization<'db> { Specialization::new(db, self.generic_context(db), types, None, None) } + #[must_use] + pub(crate) fn normalized(self, db: &'db dyn Db) -> Self { + self.normalized_impl(db, &NormalizedVisitor::default()) + } + pub(crate) fn normalized_impl(self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self { let types: Box<[_]> = self .types(db)