Skip to content

Commit a28f562

Browse files
committed
normalize for consistent output
1 parent b3f85fe commit a28f562

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
@@ -8217,10 +8217,11 @@ impl<'db> KnownInstanceType<'db> {
82178217
)
82188218
}
82198219
KnownInstanceType::Specialization(specialization) => {
8220+
// Normalize for consistent output across CI platforms
82208221
write!(
82218222
f,
82228223
"ty_extensions.Specialization{}",
8223-
specialization.display_full(self.db)
8224+
specialization.normalized(self.db).display_full(self.db)
82248225
)
82258226
}
82268227
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)