diff --git a/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll b/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll index ee797a1caa2a..64f768290e25 100644 --- a/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll +++ b/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll @@ -829,10 +829,16 @@ Function findFunctionAccordingToMro(Class cls, string name) { result = cls.getAMethod() and result.getName() = name or - not cls.getAMethod().getName() = name and + not class_has_method(cls, name) and result = findFunctionAccordingToMro(getNextClassInMro(cls), name) } +/** + * Join-order helper for `findFunctionAccordingToMro` and `findFunctionAccordingToMroKnownStartingClass`. + */ +pragma[nomagic] +private predicate class_has_method(Class cls, string name) { cls.getAMethod().getName() = name } + /** * Gets a class that, from an approximated MRO calculation, might be the next class * after `cls` in the MRO for `startingClass`. @@ -860,7 +866,7 @@ private Function findFunctionAccordingToMroKnownStartingClass( result.getName() = name and cls = getADirectSuperclass*(startingClass) or - not cls.getAMethod().getName() = name and + not class_has_method(cls, name) and result = findFunctionAccordingToMroKnownStartingClass(getNextClassInMroKnownStartingClass(cls, startingClass), startingClass, name)