mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
[ty] Fix subtyping for dynamic specializations (#20592)
## Summary Fixes a bug observed by @AlexWaygood where `C[Any] <: C[object]` should hold for a class that is covariant in its type parameter (and similar subtyping relations involving dynamic types for other variance configurations). ## Test Plan New and updated Markdown tests
This commit is contained in:
parent
2af8c53110
commit
3932f7c849
3 changed files with 26 additions and 32 deletions
|
@ -841,18 +841,6 @@ impl<'db> Specialization<'db> {
|
|||
.zip(self.types(db))
|
||||
.zip(other.types(db))
|
||||
{
|
||||
// As an optimization, we can return early if either type is dynamic, unless
|
||||
// we're dealing with a top or bottom materialization.
|
||||
if other_materialization_kind.is_none()
|
||||
&& self_materialization_kind.is_none()
|
||||
&& (self_type.is_dynamic() || other_type.is_dynamic())
|
||||
{
|
||||
match relation {
|
||||
TypeRelation::Assignability => continue,
|
||||
TypeRelation::Subtyping => return ConstraintSet::from(false),
|
||||
}
|
||||
}
|
||||
|
||||
// Subtyping/assignability of each type in the specialization depends on the variance
|
||||
// of the corresponding typevar:
|
||||
// - covariant: verify that self_type <: other_type
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue