File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed
crates/ty_python_semantic Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,20 @@ class B(A):
203
203
class C (B , A ): ... # fine
204
204
```
205
205
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
+
206
220
## False negatives
207
221
208
222
### Possibly unbound
Original file line number Diff line number Diff line change @@ -458,12 +458,12 @@ impl<'db> ClassType<'db> {
458
458
return true ;
459
459
}
460
460
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) ;
463
464
}
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 ) ;
467
467
}
468
468
469
469
// Two solid bases can only coexist in an MRO if one is a subclass of the other.
You can’t perform that action at this time.
0 commit comments