|
15 | 15 | import python |
16 | 16 | import semmle.python.dataflow.new.DataFlow |
17 | 17 | import semmle.python.dataflow.new.internal.DataFlowDispatch |
| 18 | +import codeql.util.Option |
18 | 19 |
|
19 | 20 | predicate overrides(Function base, Function sub) { |
20 | 21 | base.getName() = sub.getName() and |
@@ -54,7 +55,7 @@ predicate weakSignatureMismatch(Function base, Function sub, string msg) { |
54 | 55 | msg = |
55 | 56 | "requires " + |
56 | 57 | plural(sub.getMinPositionalArguments() - base.getMinPositionalArguments(), |
57 | | - "more positional argument") + "than some possible calls to overridden $@." |
| 58 | + "more positional argument") + " than some possible calls to overridden $@." |
58 | 59 | or |
59 | 60 | sub.getMaxPositionalArguments() < base.getMaxPositionalArguments() and |
60 | 61 | msg = |
@@ -173,16 +174,28 @@ Call chooseASignatureMismatchWitness(Function base, Function sub) { |
173 | 174 | ) |
174 | 175 | } |
175 | 176 |
|
176 | | -from Function base, Function sub, string msg, string extraMsg, Call call |
| 177 | +module CallOption = LocOption2<Location, Call>; |
| 178 | + |
| 179 | +from Function base, Function sub, string msg, string extraMsg, CallOption::Option call |
177 | 180 | where |
178 | 181 | not sub.isSpecialMethod() and |
179 | 182 | sub.getName() != "__init__" and |
180 | 183 | not ignore(sub) and |
181 | 184 | not ignore(base) and |
182 | 185 | matchingStatic(base, sub) and |
183 | | - weakSignatureMismatch(base, sub, msg) and |
184 | | - //msg = " has a different signature to $@." and |
185 | | - call = chooseASignatureMismatchWitness(base, sub) and |
186 | | - extraMsg = |
187 | | - " $@ correctly calls the base method, but does not match the signature of the overriding method." |
| 186 | + ( |
| 187 | + call.asSome() = chooseASignatureMismatchWitness(base, sub) and |
| 188 | + extraMsg = |
| 189 | + " $@ correctly calls the base method, but does not match the signature of the overriding method." and |
| 190 | + ( |
| 191 | + strongSignatureMismatch(base, sub, msg) |
| 192 | + or |
| 193 | + not strongSignatureMismatch(base, sub, _) and |
| 194 | + weakSignatureMismatch(base, sub, msg) |
| 195 | + ) |
| 196 | + or |
| 197 | + not exists(getASignatureMismatchWitness(base, sub)) and |
| 198 | + strongSignatureMismatch(base, sub, msg) and |
| 199 | + extraMsg = "" |
| 200 | + ) |
188 | 201 | select sub, "This method " + msg + extraMsg, base, base.getQualifiedName(), call, "This call" |
0 commit comments