Skip to content

Commit

Permalink
is_subclass_of should not respect Any/Unknown in bases
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Oct 18, 2024
1 parent 3365566 commit 985b235
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class Y(Foo):
pass

# TODO: Should be `int | Unknown`; see above discussion.
reveal_type(X() + Y()) # revealed: Unknown
reveal_type(X() + Y()) # revealed: int
```

## Unsupported
Expand Down
4 changes: 3 additions & 1 deletion crates/red_knot_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,9 @@ impl<'db> ClassType<'db> {
(other == self)
|| self.bases(db).any(|base| match base {
Type::Class(base_class) => base_class == other,
Type::Any | Type::Unknown => true,
// `is_subclass_of` is checking the subtype relation, in which gradual types do not
// participate, so we should not return `True` if we find `Any/Unknown` in the
// bases.
_ => false,
})
}
Expand Down

0 comments on commit 985b235

Please sign in to comment.