Skip to content

Commit 4185edc

Browse files
committed
Python: Expand parameters/functions test
I want to ensure we handle when only _some_ parameters have default/annotations
1 parent 0cc8d49 commit 4185edc

12 files changed

+71
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ class CallableValue extends Value {
383383
exists(int n |
384384
call.getArg(n) = result and
385385
this.(PythonFunctionObjectInternal).getScope().getArg(n + offset).getName() = name
386+
// TODO: and not positional only argument (Python 3.8+)
386387
)
387388
or
388389
call.getArgByName(name) = result and

python/ql/test/3/library-tests/functions/Function.getAChildNode.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
| test.py:4:1:11:2 | Function func | test.py:12:5:12:41 | ExprStmt |
66
| test.py:4:1:11:2 | Function func | test.py:13:5:13:15 | ExprStmt |
77
| test.py:4:1:11:2 | Function func | test.py:14:5:14:17 | ExprStmt |
8+
| test.py:23:1:31:2 | Function func2 | test.py:24:5:24:11 | pos_req |
9+
| test.py:23:1:31:2 | Function func2 | test.py:25:5:25:17 | pos_w_default |
10+
| test.py:23:1:31:2 | Function func2 | test.py:26:5:26:18 | pos_w_default2 |
11+
| test.py:23:1:31:2 | Function func2 | test.py:32:5:32:18 | ExprStmt |
12+
| test.py:23:1:31:2 | Function func2 | test.py:33:5:40:5 | ExprStmt |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
| test.py:4:1:11:2 | Function func | 0 | test.py:5:5:5:12 | Parameter |
22
| test.py:4:1:11:2 | Function func | 1 | test.py:7:5:7:10 | Parameter |
3+
| test.py:23:1:31:2 | Function func2 | 0 | test.py:24:5:24:11 | Parameter |
4+
| test.py:23:1:31:2 | Function func2 | 1 | test.py:25:5:25:17 | Parameter |
5+
| test.py:23:1:31:2 | Function func2 | 2 | test.py:26:5:26:18 | Parameter |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
| test.py:4:1:11:2 | Function func | normal | test.py:7:5:7:10 | Parameter |
22
| test.py:4:1:11:2 | Function func | pos_only | test.py:5:5:5:12 | Parameter |
3+
| test.py:23:1:31:2 | Function func2 | pos_req | test.py:24:5:24:11 | Parameter |
4+
| test.py:23:1:31:2 | Function func2 | pos_w_default | test.py:25:5:25:17 | Parameter |
5+
| test.py:23:1:31:2 | Function func2 | pos_w_default2 | test.py:26:5:26:18 | Parameter |

python/ql/test/3/library-tests/functions/FunctionExpr.getASubExpression.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
| test.py:4:1:11:2 | FunctionExpr | test.py:8:12:8:23 | Str |
66
| test.py:4:1:11:2 | FunctionExpr | test.py:9:25:9:26 | UnaryExpr |
77
| test.py:4:1:11:2 | FunctionExpr | test.py:10:15:10:30 | Str |
8+
| test.py:23:1:31:2 | FunctionExpr | test.py:25:20:25:24 | Str |
9+
| test.py:23:1:31:2 | FunctionExpr | test.py:25:28:25:31 | None |
10+
| test.py:23:1:31:2 | FunctionExpr | test.py:26:20:26:23 | None |
11+
| test.py:23:1:31:2 | FunctionExpr | test.py:29:32:29:35 | None |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:5:21:5:22 | UnaryExpr |
22
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:7:19:7:20 | UnaryExpr |
3+
| test.py:23:1:31:2 | FunctionExpr | Arguments | test.py:25:28:25:31 | None |
4+
| test.py:23:1:31:2 | FunctionExpr | Arguments | test.py:26:20:26:23 | None |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:9:25:9:26 | UnaryExpr |
2+
| test.py:23:1:31:2 | FunctionExpr | Arguments | test.py:29:32:29:35 | None |

python/ql/test/3/library-tests/functions/test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,26 @@ def func(
1818
func(4, normal=5, keyword_only=6)
1919

2020
func(1, 2, "varargs0", "varargs1", keyword_only=3, kwargs0="0", kwargs1="1")
21+
22+
23+
def func2(
24+
pos_req,
25+
pos_w_default: "foo" = None,
26+
pos_w_default2=None,
27+
*,
28+
keyword_req,
29+
keyword_w_default: "foo" = None,
30+
keyword_also_req,
31+
):
32+
print("func2")
33+
print(
34+
pos_req,
35+
pos_w_default,
36+
pos_w_default2,
37+
keyword_req,
38+
keyword_w_default,
39+
keyword_also_req,
40+
)
41+
42+
43+
func2(1, keyword_req=2, keyword_also_req=3)

python/ql/test/3/library-tests/parameters/Annotations.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
| kwargs | test.py:10:15:10:30 | Str |
33
| normal | test.py:7:13:7:15 | int |
44
| pos_only | test.py:5:15:5:17 | int |
5+
| pos_w_default | test.py:25:20:25:24 | Str |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
| normal | test.py:7:19:7:20 | UnaryExpr |
22
| pos_only | test.py:5:21:5:22 | UnaryExpr |
3+
| pos_w_default | test.py:25:28:25:31 | None |
4+
| pos_w_default2 | test.py:26:20:26:23 | None |

0 commit comments

Comments
 (0)