Python: Exclude "self-inheritance" results

It's not possible for a class to actually inherit from itself, so if
this happens, something has gone wrong with our analysis. We therefore
explicitly exclude these results so they don't result in false
positives.
This commit is contained in:
Taus
2026-04-09 21:12:17 +00:00
parent adbc4a7777
commit 5e34778d72

View File

@@ -17,7 +17,10 @@ private import semmle.python.dataflow.new.internal.DataFlowDispatch
/**
* Gets the `i`th base class of `cls`, if it can be resolved to a user-defined class.
*/
Class getBaseType(Class cls, int i) { cls.getBase(i) = classTracker(result).asExpr() }
Class getBaseType(Class cls, int i) {
cls.getBase(i) = classTracker(result).asExpr() and
result != cls
}
Class left_base(Class type, Class base) {
exists(int i | i > 0 and getBaseType(type, i) = base and result = getBaseType(type, i - 1))