Skip to content

Commit 1fcbb6e

Browse files
committed
Python: Better test for Argument.getDefault(i)
Default values for positional arugments follow a rule, so if an argument has a default value, later positional arguments must also have default values. The database only stores the actual default values, and nothing about the arguments that doesn't have default values. This turns out to be a major problem for Argument.getKwDefault(i), since default values for keyword-only arguments doesn't have the same rule. So if you know there is one default value, you can't tell if it is associated with `foo` or `bar`, as in the examples below: ``` def a(*, foo=None, bar): pass def b(*, foo, bar=None): pass ```
1 parent 5f60583 commit 1fcbb6e

12 files changed

+27
-14
lines changed

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

Lines changed: 0 additions & 4 deletions
This file was deleted.

python/ql/test/3/library-tests/functions/FunctionExpr.getArgs.getADefault.ql

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 0 additions & 2 deletions
This file was deleted.

python/ql/test/3/library-tests/functions/FunctionExpr.getArgs.getAKwDefault.ql

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.py:4:1:11:2 | FunctionExpr | 0 | test.py:5:15:5:17 | int |
2+
| test.py:4:1:11:2 | FunctionExpr | 1 | test.py:7:13:7:15 | int |
3+
| test.py:23:1:31:2 | FunctionExpr | 1 | test.py:25:20:25:24 | Str |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import python
2+
3+
from FunctionExpr fe, int i
4+
select fe, i, fe.getArgs().getAnnotation(i)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.py:4:1:11:2 | FunctionExpr | 0 | test.py:5:21:5:22 | UnaryExpr |
2+
| test.py:4:1:11:2 | FunctionExpr | 1 | test.py:7:19:7:20 | UnaryExpr |
3+
| test.py:23:1:31:2 | FunctionExpr | 0 | test.py:25:28:25:31 | None |
4+
| test.py:23:1:31:2 | FunctionExpr | 1 | test.py:26:20:26:23 | None |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import python
2+
3+
from FunctionExpr fe, int i
4+
select fe, i, fe.getArgs().getDefault(i)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.py:4:1:11:2 | FunctionExpr | 0 | test.py:9:19:9:21 | int |
2+
| test.py:23:1:31:2 | FunctionExpr | 1 | test.py:29:24:29:28 | Str |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import python
2+
3+
from FunctionExpr fe, int i
4+
select fe, i, fe.getArgs().getKwAnnotation(i)

0 commit comments

Comments
 (0)