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.
This commit is contained in:
Taus
2026-03-24 13:04:44 +00:00
parent ac48eca916
commit 059693ce89

View File

@@ -19,7 +19,7 @@ private import semmle.python.dataflow.new.internal.DataFlowDispatch
from Class c
where
not DuckTyping::isContextManager(c) and
DuckTyping::hasMethod(c, "__del__")
exists(c.getMethod("__del__"))
select c,
"Class " + c.getName() +
" implements __del__ (presumably to release some resource). Consider making it a context manager."