Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,6 @@ reveal_type(Sub) # revealed: <class 'Sub'>
U = TypeVar("U")

class Base2(Generic[T, U]): ...

# TODO: no error
# error: [unsupported-base] "Unsupported class base with type `<class 'Base2[Sub2, U@Sub2]'> | <class 'Base2[Sub2[Unknown], U@Sub2]'>`"
class Sub2(Base2["Sub2", U]): ...
```

Expand All @@ -888,8 +885,6 @@ from typing_extensions import Generic, TypeVar

T = TypeVar("T")

# TODO: no error "Unsupported class base with type `<class 'list[Derived[T@Derived]]'> | <class 'list[@Todo]'>`"
# error: [unsupported-base]
class Derived(list[Derived[T]], Generic[T]): ...
```

Expand Down
15 changes: 13 additions & 2 deletions crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,19 @@ impl<'db> Type<'db> {
previous: Self,
cycle: &salsa::Cycle,
) -> Self {
UnionType::from_elements_cycle_recovery(db, [self, previous])
.recursive_type_normalized(db, cycle)
// Avoid unioning two generic aliases of the same class together; this union will never
// simplify and is likely to cause downstream problems. This introduces the theoretical
// possibility of cycle oscillation involving such types (because we are not strictly
// widening the type on each iteration), but so far we have not seen an example of that.
match (previous, self) {
(Type::GenericAlias(prev_alias), Type::GenericAlias(curr_alias))
if prev_alias.origin(db) == curr_alias.origin(db) =>
{
self
}
_ => UnionType::from_elements_cycle_recovery(db, [self, previous]),
}
.recursive_type_normalized(db, cycle)
}

fn is_none(&self, db: &'db dyn Db) -> bool {
Expand Down
Loading