Skip to content

Commit 6b589c5

Browse files
authored
Merge pull request #10387 from RasmusWL/getStarArg-always-first
Python: `getStarArg` gives first `*args` argument
2 parents b49487c + 41ce1c2 commit 6b589c5

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* `getStarArg` member-predicate on `Call` and `CallNode` has been changed for calls that have multiple `*args` arguments (for example `func(42, *my_args, *other_args)`): Instead of producing no results, it will always have a result for the _first_ such `*args` argument.

python/ql/lib/semmle/python/Exprs.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,12 @@ class Call extends Call_ {
245245
result = count(Expr arg | arg = this.getAPositionalArg() and not arg instanceof Starred)
246246
}
247247

248-
/** Gets the tuple (*) argument of this call, provided there is exactly one. */
248+
/** Gets the first tuple (*) argument of this call, if any. */
249249
Expr getStarArg() {
250-
count(this.getStarargs()) < 2 and
251-
result = this.getStarargs()
250+
exists(int firstStarArgIndex |
251+
firstStarArgIndex = min(int i | this.getPositionalArg(i) instanceof Starred | i) and
252+
result = this.getPositionalArg(firstStarArgIndex).(Starred).getValue()
253+
)
252254
}
253255
}
254256

python/ql/lib/semmle/python/Flow.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class CallNode extends ControlFlowNode {
406406
exists(FunctionExpr func | this.getNode() = func.getADecoratorCall())
407407
}
408408

409-
/** Gets the tuple (*) argument of this call, provided there is exactly one. */
409+
/** Gets the first tuple (*) argument of this call, if any. */
410410
ControlFlowNode getStarArg() {
411411
result.getNode() = this.getNode().getStarArg() and
412412
result.getBasicBlock().dominates(this.getBasicBlock())

0 commit comments

Comments
 (0)