Skip to content

Commit 5e902dd

Browse files
committed
remove redundant check and add Carl's other test
1 parent 242ccab commit 5e902dd

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

crates/ty_python_semantic/resources/mdtest/slots.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,20 @@ class B(A):
203203
class C(B, A): ... # fine
204204
```
205205

206+
The same principle, but a more complex example:
207+
208+
```py
209+
class AA:
210+
__slots__ = ("a",)
211+
212+
class BB(AA):
213+
__slots__ = ("b",)
214+
215+
class CC(BB): ...
216+
class DD(AA): ...
217+
class FF(CC, DD): ... # fine
218+
```
219+
206220
## False negatives
207221

208222
### Possibly unbound

crates/ty_python_semantic/src/types/class.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,12 @@ impl<'db> ClassType<'db> {
458458
return true;
459459
}
460460

461-
if self.is_subclass_of(db, other) || other.is_subclass_of(db, self) {
462-
return true;
461+
// Optimisation: if either class is `@final`, we only need to do one `is_subclass_of` call.
462+
if self.is_final(db) {
463+
return self.is_subclass_of(db, other);
463464
}
464-
465-
if self.is_final(db) || other.is_final(db) {
466-
return false;
465+
if other.is_final(db) {
466+
return other.is_subclass_of(db, self);
467467
}
468468

469469
// Two solid bases can only coexist in an MRO if one is a subclass of the other.

0 commit comments

Comments
 (0)