Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion crates/ty_python_semantic/src/types/cyclic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ impl<'db> Type<'db> {
a.definition(db) == b.definition(db)
}
(Type::TypeAlias(a), Type::TypeAlias(b)) => a.definition(db) == b.definition(db),
(Type::TypedDict(a), Type::TypedDict(b)) => a.definition(db) == b.definition(db),
(
Type::TypedDict(TypedDictType::Class(a)),
Type::TypedDict(TypedDictType::Class(b)),
) => {
// Different specializations of the same recursive TypedDict can form a cycle.
// Each class statement has a unique body scope, so comparing scopes tells us
// whether the types came from the same class, even after decorators.
// Other TypedDicts can only match by exact equality, which we checked above.
matches!(
(a.class_literal(db).as_static(), b.class_literal(db).as_static()),
(Some(a), Some(b)) if a.body_scope(db) == b.body_scope(db)
)
}
(Type::Recursive(a), Type::Recursive(b)) => a.definition(db) == b.definition(db),
_ => false,
}
Expand Down
Loading