|
1 | 1 | /** |
2 | | - * @name Missing call to `__del__` during object destruction |
3 | | - * @description An omitted call to a super-class `__del__` method may lead to class instances not being cleaned up properly. |
| 2 | + * @name Missing call to superclass `__del__` during object destruction |
| 3 | + * @description An omitted call to a superclass `__del__` method may lead to class instances not being cleaned up properly. |
4 | 4 | * @kind problem |
5 | 5 | * @tags quality |
6 | 6 | * reliability |
|
15 | 15 | import python |
16 | 16 | import MethodCallOrder |
17 | 17 |
|
18 | | -from ClassObject self, FunctionObject missing |
| 18 | +predicate missingCallToSuperclassDel(Function base, Function shouldCall, Class mroStart) { |
| 19 | + missingCallToSuperclassMethod(base, shouldCall, mroStart, "__del__") |
| 20 | +} |
| 21 | + |
| 22 | +from Function base, Function shouldCall, Class mroStart, string msg |
19 | 23 | where |
20 | | - missing_call_to_superclass_method(self, _, missing, "__del__") and |
21 | | - not missing.neverReturns() and |
22 | | - not self.failedInference() and |
23 | | - not missing.isBuiltin() |
24 | | -select self, |
25 | | - "Class " + self.getName() + " may not be cleaned up properly as $@ is not called during deletion.", |
26 | | - missing, missing.descriptiveString() |
| 24 | + missingCallToSuperclassDel(base, shouldCall, mroStart) and |
| 25 | + ( |
| 26 | + // Simple case: the method that should be called is directly overridden |
| 27 | + mroStart = base.getScope() and |
| 28 | + msg = "This deletion method does not call $@, which may leave $@ not properly cleaned up." |
| 29 | + or |
| 30 | + // Only alert for a different mro base if there are no alerts for direct overrides |
| 31 | + not missingCallToSuperclassDel(base, _, base.getScope()) and |
| 32 | + msg = |
| 33 | + "This deletion method does not call $@, which follows it in the MRO of $@, leaving it not properly cleaned up." |
| 34 | + ) |
| 35 | +select base, msg, shouldCall, shouldCall.getQualifiedName(), mroStart, mroStart.getName() |
0 commit comments