mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Python: Add tests for full Python 3 parameters syntax
Currently keyword-only parameters are not handled properly :(
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
| test.py:4:1:11:2 | Function func | test.py:5:5:5:12 | pos_only |
|
||||
| test.py:4:1:11:2 | Function func | test.py:7:5:7:10 | normal |
|
||||
| test.py:4:1:11:2 | Function func | test.py:8:6:8:9 | args |
|
||||
| test.py:4:1:11:2 | Function func | test.py:10:7:10:12 | kwargs |
|
||||
| test.py:4:1:11:2 | Function func | test.py:12:5:12:41 | ExprStmt |
|
||||
| test.py:4:1:11:2 | Function func | test.py:13:5:13:15 | ExprStmt |
|
||||
| test.py:4:1:11:2 | Function func | test.py:14:5:14:17 | ExprStmt |
|
||||
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from Function f
|
||||
select f, f.getAChildNode()
|
||||
@@ -0,0 +1,2 @@
|
||||
| test.py:4:1:11:2 | Function func | 0 | test.py:5:5:5:12 | Parameter |
|
||||
| test.py:4:1:11:2 | Function func | 1 | test.py:7:5:7:10 | Parameter |
|
||||
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from Function f, int i
|
||||
select f, i, f.getArg(i)
|
||||
@@ -0,0 +1,2 @@
|
||||
| test.py:4:1:11:2 | Function func | normal | test.py:7:5:7:10 | Parameter |
|
||||
| test.py:4:1:11:2 | Function func | pos_only | test.py:5:5:5:12 | Parameter |
|
||||
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from Function f, string name
|
||||
select f, name, f.getArgByName(name)
|
||||
@@ -0,0 +1,7 @@
|
||||
| test.py:4:1:11:2 | FunctionExpr | test.py:5:15:5:17 | int |
|
||||
| test.py:4:1:11:2 | FunctionExpr | test.py:5:21:5:22 | UnaryExpr |
|
||||
| test.py:4:1:11:2 | FunctionExpr | test.py:7:13:7:15 | int |
|
||||
| test.py:4:1:11:2 | FunctionExpr | test.py:7:19:7:20 | UnaryExpr |
|
||||
| test.py:4:1:11:2 | FunctionExpr | test.py:8:12:8:23 | Str |
|
||||
| test.py:4:1:11:2 | FunctionExpr | test.py:9:25:9:26 | UnaryExpr |
|
||||
| test.py:4:1:11:2 | FunctionExpr | test.py:10:15:10:30 | Str |
|
||||
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from FunctionExpr fe
|
||||
select fe, fe.getASubExpression()
|
||||
@@ -0,0 +1,2 @@
|
||||
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:5:21:5:22 | UnaryExpr |
|
||||
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:7:19:7:20 | UnaryExpr |
|
||||
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from FunctionExpr fe
|
||||
select fe, fe.getArgs(), fe.getArgs().getADefault()
|
||||
@@ -0,0 +1 @@
|
||||
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:9:25:9:26 | UnaryExpr |
|
||||
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from FunctionExpr fe
|
||||
select fe, fe.getArgs(), fe.getArgs().getAKwDefault()
|
||||
20
python/ql/test/3/library-tests/functions/test.py
Normal file
20
python/ql/test/3/library-tests/functions/test.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# not importing typing so we don't need to filter by location in Ql tests
|
||||
|
||||
|
||||
def func(
|
||||
pos_only: int = -1,
|
||||
/,
|
||||
normal: int = -2,
|
||||
*args: "Tuple[str]",
|
||||
keyword_only: int = -3,
|
||||
**kwargs: "Dict[str, str]",
|
||||
):
|
||||
print(pos_only, normal, keyword_only)
|
||||
print(args)
|
||||
print(kwargs)
|
||||
|
||||
|
||||
func(1, 2, keyword_only=3)
|
||||
func(4, normal=5, keyword_only=6)
|
||||
|
||||
func(1, 2, "varargs0", "varargs1", keyword_only=3, kwargs0="0", kwargs1="1")
|
||||
@@ -0,0 +1,4 @@
|
||||
| args | test.py:8:12:8:23 | Str |
|
||||
| kwargs | test.py:10:15:10:30 | Str |
|
||||
| normal | test.py:7:13:7:15 | int |
|
||||
| pos_only | test.py:5:15:5:17 | int |
|
||||
4
python/ql/test/3/library-tests/parameters/Annotations.ql
Normal file
4
python/ql/test/3/library-tests/parameters/Annotations.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from Parameter p
|
||||
select p.getName(), p.getAnnotation()
|
||||
@@ -0,0 +1,2 @@
|
||||
| normal | test.py:7:19:7:20 | UnaryExpr |
|
||||
| pos_only | test.py:5:21:5:22 | UnaryExpr |
|
||||
4
python/ql/test/3/library-tests/parameters/Defaults.ql
Normal file
4
python/ql/test/3/library-tests/parameters/Defaults.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from Parameter p
|
||||
select p.getName(), p.getDefault()
|
||||
@@ -0,0 +1,4 @@
|
||||
| args | varargs |
|
||||
| kwargs | kwargs |
|
||||
| normal | normal |
|
||||
| pos_only | normal |
|
||||
10
python/ql/test/3/library-tests/parameters/Special.ql
Normal file
10
python/ql/test/3/library-tests/parameters/Special.ql
Normal file
@@ -0,0 +1,10 @@
|
||||
import python
|
||||
|
||||
from Parameter p, string type
|
||||
where
|
||||
p.isKwargs() and type = "kwargs"
|
||||
or
|
||||
p.isVarargs() and type = "varargs"
|
||||
or
|
||||
not p.isKwargs() and not p.isVarargs() and type = "normal"
|
||||
select p.getName(), type
|
||||
20
python/ql/test/3/library-tests/parameters/test.py
Normal file
20
python/ql/test/3/library-tests/parameters/test.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# not importing typing so we don't need to filter by location in Ql tests
|
||||
|
||||
|
||||
def func(
|
||||
pos_only: int = -1,
|
||||
/,
|
||||
normal: int = -2,
|
||||
*args: "Tuple[str]",
|
||||
keyword_only: int = -3,
|
||||
**kwargs: "Dict[str, str]",
|
||||
):
|
||||
print(pos_only, normal, keyword_only)
|
||||
print(args)
|
||||
print(kwargs)
|
||||
|
||||
|
||||
func(1, 2, keyword_only=3)
|
||||
func(4, normal=5, keyword_only=6)
|
||||
|
||||
func(1, 2, "varargs0", "varargs1", keyword_only=3, kwargs0="0", kwargs1="1")
|
||||
Reference in New Issue
Block a user