Skip to content

Commit 838106d

Browse files
committed
Python: Refactor get[Named]ArgumentForCall
Also fixed a bug for BoundMethodValue, as highlighted in the expected diff 👍
1 parent bc92c26 commit 838106d

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,7 @@ class CallableValue extends Value {
363363
or
364364
exists(string name |
365365
call.getArgByName(name) = result and
366-
(
367-
this.(PythonFunctionObjectInternal).getScope().getArg(n).getName() = name
368-
or
369-
this.(BoundMethodObjectInternal).getFunction().getScope().getArg(n+1).getName() = name
370-
)
366+
this.getParameter(n).getId() = name
371367
)
372368
or
373369
called instanceof BoundMethodObjectInternal and
@@ -386,19 +382,11 @@ class CallableValue extends Value {
386382
|
387383
exists(int n |
388384
call.getArg(n) = result and
389-
exists(PythonFunctionObjectInternal py |
390-
py = this or py = this.(BoundMethodObjectInternal).getFunction()
391-
|
392-
py.getScope().getArg(n + offset).getName() = name
393-
)
385+
this.getParameter(n+offset).getId() = name
394386
)
395387
or
396388
call.getArgByName(name) = result and
397-
exists(PythonFunctionObjectInternal py |
398-
py = this or py = this.(BoundMethodObjectInternal).getFunction()
399-
|
400-
exists(py.getScope().getArgByName(name))
401-
)
389+
exists(this.getParameterByName(name))
402390
or
403391
called instanceof BoundMethodObjectInternal and
404392
offset = 1 and

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
| 23 | ControlFlowNode for Attribute() | Function f | arg1 | ControlFlowNode for w |
88
| 23 | ControlFlowNode for Attribute() | Function f | arg2 | ControlFlowNode for z |
99
| 23 | ControlFlowNode for Attribute() | Function f | self | ControlFlowNode for c |
10-
| 23 | ControlFlowNode for Attribute() | Method(Function f, C()) | arg0 | ControlFlowNode for w |
11-
| 23 | ControlFlowNode for Attribute() | Method(Function f, C()) | arg1 | ControlFlowNode for z |
10+
| 23 | ControlFlowNode for Attribute() | Method(Function f, C()) | arg1 | ControlFlowNode for w |
11+
| 23 | ControlFlowNode for Attribute() | Method(Function f, C()) | arg2 | ControlFlowNode for z |
1212
| 24 | ControlFlowNode for Attribute() | Function C.n | arg1 | ControlFlowNode for x |
1313
| 24 | ControlFlowNode for Attribute() | Function C.n | self | ControlFlowNode for c |
14-
| 24 | ControlFlowNode for Attribute() | Method(Function C.n, C()) | self | ControlFlowNode for x |
14+
| 24 | ControlFlowNode for Attribute() | Method(Function C.n, C()) | arg1 | ControlFlowNode for x |
1515
| 25 | ControlFlowNode for Attribute() | Function C.n | arg1 | ControlFlowNode for z |
1616
| 25 | ControlFlowNode for Attribute() | Function C.n | self | ControlFlowNode for y |
1717
| 33 | ControlFlowNode for Attribute() | Function D.foo | arg | ControlFlowNode for IntegerLiteral |

0 commit comments

Comments
 (0)