Skip to content

Commit 5e34778

Browse files
committed
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.
1 parent adbc4a7 commit 5e34778

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

python/ql/src/Classes/InconsistentMRO.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ private import semmle.python.dataflow.new.internal.DataFlowDispatch
1717
/**
1818
* Gets the `i`th base class of `cls`, if it can be resolved to a user-defined class.
1919
*/
20-
Class getBaseType(Class cls, int i) { cls.getBase(i) = classTracker(result).asExpr() }
20+
Class getBaseType(Class cls, int i) {
21+
cls.getBase(i) = classTracker(result).asExpr() and
22+
result != cls
23+
}
2124

2225
Class left_base(Class type, Class base) {
2326
exists(int i | i > 0 and getBaseType(type, i) = base and result = getBaseType(type, i - 1))

0 commit comments

Comments
 (0)