Skip to content

Commit 49d7e12

Browse files
committed
Python: Remove unnecessary restriction from getNamedArgumentForCall
As agreed in #3407
1 parent 4fc3cae commit 49d7e12

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

python/ql/src/semmle/python/objects/ObjectAPI.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ class CallableValue extends Value {
397397

398398
/**
399399
* Gets the argument in `call` corresponding to the `name`d keyword parameter of this callable.
400-
* ONLY WORKS FOR NON-BUILTINS.
401400
*
402401
* This method also gives results when the argument is passed as a positional argument in `call`, as long
403402
* as `this` is not a builtin function or a builtin method.
@@ -420,8 +419,7 @@ class CallableValue extends Value {
420419
PointsToInternal::pointsTo(call.getFunction(), _, called, _) and
421420
called.functionAndOffset(this, offset)
422421
|
423-
call.getArgByName(name) = result and
424-
exists(this.getParameterByName(name))
422+
call.getArgByName(name) = result
425423
or
426424
exists(int n |
427425
call.getArg(n) = result and

python/ql/test/library-tests/PointsTo/calls/getNamedArgumentForCall.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@
2323
| 42 | ControlFlowNode for Attribute() | Function C.n | arg1 | ControlFlowNode for IntegerLiteral |
2424
| 42 | ControlFlowNode for Attribute() | Function C.n | self | ControlFlowNode for c |
2525
| 42 | ControlFlowNode for Attribute() | Method(Function C.n, C()) | arg1 | ControlFlowNode for IntegerLiteral |
26+
| 46 | ControlFlowNode for open() | Builtin-function open | file | ControlFlowNode for Str |
27+
| 46 | ControlFlowNode for open() | Builtin-function open | mode | ControlFlowNode for Str |
2628
| 51 | ControlFlowNode for foo() | Function foo | a | ControlFlowNode for IntegerLiteral |
2729
| 55 | ControlFlowNode for bar() | Function bar | a | ControlFlowNode for IntegerLiteral |
30+
| 55 | ControlFlowNode for bar() | Function bar | b | ControlFlowNode for IntegerLiteral |
31+
| 55 | ControlFlowNode for bar() | Function bar | c | ControlFlowNode for IntegerLiteral |

python/ql/test/library-tests/PointsTo/calls/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def foo(arg):
4343

4444
# positional/keyword arguments for a builtin function
4545
open("foo.txt", "rb") # TODO: Not handled by getNamedArgumentForCall
46-
open(file="foo.txt", mode="rb") # TODO: Not handled by either getNamedArgumentForCall or getArgumentForCall
46+
open(file="foo.txt", mode="rb")
4747

4848
# Testing how arguments to *args and **kwargs are handled
4949
def foo(a, *args):
@@ -52,4 +52,4 @@ def foo(a, *args):
5252

5353
def bar(a, **kwargs):
5454
pass
55-
bar(a=1, b=2, c=3) # TODO: no result for `b` or `c` with getNamedArgumentForCall
55+
bar(a=1, b=2, c=3)

0 commit comments

Comments
 (0)