Skip to content

Commit 6f9983a

Browse files
Add missing call to del
1 parent a2fc14a commit 6f9983a

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
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.
44
* @kind problem
55
* @tags quality
66
* reliability
@@ -15,12 +15,21 @@
1515
import python
1616
import MethodCallOrder
1717

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
1923
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()

python/ql/src/Classes/CallsToInitDel/MissingCallToInit.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Missing call to superclass `__init__` during object initialization
3-
* @description An omitted call to a super-class `__init__` method may lead to objects of this class not being fully initialized.
3+
* @description An omitted call to a superclass `__init__` method may lead to objects of this class not being fully initialized.
44
* @kind problem
55
* @tags quality
66
* reliability

0 commit comments

Comments
 (0)