Skip to content

Commit a276f72

Browse files
committed
Python: Add ternary overridesMethod
This one also allows easy access to the method being overridden and the class on which it resides. This let's us simplify DocStrings.ql accordingly.
1 parent 1ffcdc9 commit a276f72

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,8 +2135,18 @@ module DuckTyping {
21352135
/**
21362136
* Holds if `f` overrides a method in a superclass with the same name.
21372137
*/
2138-
predicate overridesMethod(Function f) {
2139-
exists(Class cls | f.getScope() = cls | hasMethod(getADirectSuperclass(cls), f.getName()))
2138+
predicate overridesMethod(Function f) { overridesMethod(f, _, _) }
2139+
2140+
/**
2141+
* Holds if `f` overrides `overridden` declared in `superclass`.
2142+
*/
2143+
predicate overridesMethod(Function f, Class superclass, Function overridden) {
2144+
exists(Class cls |
2145+
f.getScope() = cls and
2146+
superclass = getADirectSuperclass+(cls) and
2147+
overridden = superclass.getAMethod() and
2148+
overridden.getName() = f.getName()
2149+
)
21402150
}
21412151

21422152
/**

python/ql/src/Statements/DocStrings.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ predicate needs_docstring(Scope s) {
3030

3131
predicate function_needs_docstring(FunctionMetrics f) {
3232
not exists(Function base |
33-
DuckTyping::overridesMethod(f) and
34-
base.getScope() = getADirectSuperclass+(f.getScope()) and
35-
base.getName() = f.getName() and
33+
DuckTyping::overridesMethod(f, _, base) and
3634
not function_needs_docstring(base)
3735
) and
3836
f.getName() != "lambda" and

0 commit comments

Comments
 (0)