Skip to content

Commit ea1f78f

Browse files
tausbnCopilot
andcommitted
Python: Add DuckTyping::hasUnreliableMro
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ffe1209 commit ea1f78f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,19 @@ module DuckTyping {
21182118
*/
21192119
Function getInit(Class cls) { result = invokedFunctionFromClassConstruction(cls, "__init__") }
21202120

2121+
/**
2122+
* Holds if `cls` or any of its superclasses uses multiple inheritance, or
2123+
* has an unresolved base class. In these cases, our MRO approximation may
2124+
* resolve to the wrong `__init__`, so we should not flag argument mismatches.
2125+
*/
2126+
predicate hasUnreliableMro(Class cls) {
2127+
exists(Class sup | sup = getADirectSuperclass*(cls) |
2128+
exists(sup.getBase(1))
2129+
or
2130+
hasUnresolvedBase(sup)
2131+
)
2132+
}
2133+
21212134
/**
21222135
* Holds if `f` overrides a method in a superclass with the same name.
21232136
*/

0 commit comments

Comments
 (0)