Skip to content

Commit 059693c

Browse files
committed
Python: Restrict ShouldBeContextManager.ql results
By limiting the results to the class that actually defines the `__del__` method, we eliminate a bunch of FPs where a _subclass_ of such a class would also get flagged.
1 parent ac48eca commit 059693c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

python/ql/src/Classes/ShouldBeContextManager.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private import semmle.python.dataflow.new.internal.DataFlowDispatch
1919
from Class c
2020
where
2121
not DuckTyping::isContextManager(c) and
22-
DuckTyping::hasMethod(c, "__del__")
22+
exists(c.getMethod("__del__"))
2323
select c,
2424
"Class " + c.getName() +
2525
" implements __del__ (presumably to release some resource). Consider making it a context manager."

0 commit comments

Comments
 (0)