|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import python |
18 | | -import Expressions.CallArgs |
19 | | -private import LegacyPointsTo |
| 18 | +private import semmle.python.dataflow.new.internal.DataFlowDispatch |
20 | 19 |
|
21 | | -from Call call, ClassValue cls, string name, FunctionValue init |
| 20 | +/** |
| 21 | + * Holds if `name` is a legal argument name for calling `init`. |
| 22 | + */ |
| 23 | +bindingset[name] |
| 24 | +predicate isLegalArgumentName(Function init, string name) { |
| 25 | + exists(init.getArgByName(name)) |
| 26 | + or |
| 27 | + init.hasKwArg() |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Holds if `call` constructs class `cls` and passes a keyword argument `name` |
| 32 | + * that does not correspond to any parameter of `cls.__init__`. |
| 33 | + */ |
| 34 | +predicate illegally_named_parameter(Call call, Class cls, string name) { |
| 35 | + exists(Function init | |
| 36 | + resolveClassCall(call.getAFlowNode(), cls) and |
| 37 | + init = DuckTyping::getInit(cls) and |
| 38 | + name = call.getANamedArgumentName() and |
| 39 | + not isLegalArgumentName(init, name) |
| 40 | + ) |
| 41 | +} |
| 42 | + |
| 43 | +from Call call, Class cls, string name, Function init |
22 | 44 | where |
23 | 45 | illegally_named_parameter(call, cls, name) and |
24 | | - init = get_function_or_initializer(cls) |
| 46 | + init = DuckTyping::getInit(cls) |
25 | 47 | select call, "Keyword argument '" + name + "' is not a supported parameter name of $@.", init, |
26 | 48 | init.getQualifiedName() |
0 commit comments