Skip to content

Commit 1c9744d

Browse files
committed
normalize for consistent output
1 parent 036c892 commit 1c9744d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

crates/ty_python_semantic/resources/mdtest/generics/specialize_constrained.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def unbounded[T]():
4343
reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(Never, T, int) | ConstraintSet.range(Never, T, bool)))
4444
# revealed: ty_extensions.Specialization[T@unbounded = int | str]
4545
reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(Never, T, int) | ConstraintSet.range(Never, T, str)))
46-
# revealed: ty_extensions.Specialization[T@unbounded = str | bool]
46+
# revealed: ty_extensions.Specialization[T@unbounded = bool | str]
4747
reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(bool, T, bool) | ConstraintSet.range(Never, T, str)))
4848
```
4949

crates/ty_python_semantic/src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8226,10 +8226,11 @@ impl<'db> KnownInstanceType<'db> {
82268226
)
82278227
}
82288228
KnownInstanceType::Specialization(specialization) => {
8229+
// Normalize for consistent output across CI platforms
82298230
write!(
82308231
f,
82318232
"ty_extensions.Specialization{}",
8232-
specialization.display_full(self.db)
8233+
specialization.normalized(self.db).display_full(self.db)
82338234
)
82348235
}
82358236
KnownInstanceType::UnionType(_) => f.write_str("types.UnionType"),

crates/ty_python_semantic/src/types/generics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,11 @@ impl<'db> Specialization<'db> {
10031003
Specialization::new(db, self.generic_context(db), types, None, None)
10041004
}
10051005

1006+
#[must_use]
1007+
pub(crate) fn normalized(self, db: &'db dyn Db) -> Self {
1008+
self.normalized_impl(db, &NormalizedVisitor::default())
1009+
}
1010+
10061011
pub(crate) fn normalized_impl(self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self {
10071012
let types: Box<[_]> = self
10081013
.types(db)

0 commit comments

Comments
 (0)