Skip to content

Commit 75e6de8

Browse files
committed
Python: Add test
1 parent f67c68d commit 75e6de8

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type_vars_without_bound
2+
| test.py:1:8:1:9 | TypeVar | T1 | TypeAlias T |
3+
| test.py:3:7:3:8 | TypeVar | T6 | Function f |
4+
| test.py:5:9:5:11 | TypeVar | T10 | Class C |
5+
type_vars_with_bound
6+
| test.py:1:12:1:17 | TypeVar | T2 | E1 | TypeAlias T |
7+
| test.py:3:11:3:16 | TypeVar | T7 | E2 | Function f |
8+
| test.py:5:14:5:20 | TypeVar | T11 | E3 | Class C |
9+
type_var_tuples
10+
| test.py:1:20:1:22 | TypeVarTuple | T3 | TypeAlias T |
11+
| test.py:3:19:3:21 | TypeVarTuple | T8 | Function f |
12+
| test.py:5:23:5:26 | TypeVarTuple | T12 | Class C |
13+
param_specs
14+
| test.py:1:25:1:28 | ParamSpec | T4 | TypeAlias T |
15+
| test.py:3:24:3:27 | ParamSpec | T9 | Function f |
16+
| test.py:5:29:5:33 | ParamSpec | T13 | Class C |
17+
type_aliases
18+
| test.py:1:1:1:34 | TypeAlias | T | T5 |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type T[T1, T2: E1, *T3, **T4] = T5
2+
3+
def f[T6, T7: E2, *T8, **T9](): ...
4+
5+
class C[T10, T11: E3, *T12, **T13]: ...
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import python
2+
3+
string pretty_name(AstNode n) {
4+
result = "Function " + n.(Function).getName()
5+
or
6+
result = "Class " + n.(ClassExpr).getName()
7+
or
8+
result = "TypeAlias " + n.(TypeAlias).getName().getId()
9+
}
10+
11+
query predicate type_vars_without_bound(TypeVar tv, string name, string parent) {
12+
tv.getName().getId() = name and
13+
not exists(tv.getBound()) and
14+
parent = pretty_name(tv.getParent().getParent())
15+
}
16+
17+
query predicate type_vars_with_bound(TypeVar tv, string name, string bound, string parent) {
18+
tv.getName().getId() = name and
19+
bound = tv.getBound().(Name).getId() and
20+
parent = pretty_name(tv.getParent().getParent())
21+
}
22+
23+
query predicate type_var_tuples(TypeVarTuple tvt, string name, string parent) {
24+
tvt.getName().getId() = name and
25+
parent = pretty_name(tvt.getParent().getParent())
26+
}
27+
28+
query predicate param_specs(ParamSpec ps, string name, string parent) {
29+
ps.getName().getId() = name and
30+
parent = pretty_name(ps.getParent().getParent())
31+
}
32+
33+
query predicate type_aliases(TypeAlias ta, string name, string value) {
34+
ta.getName().getId() = name and
35+
value = ta.getValue().(Name).getId()
36+
}

0 commit comments

Comments
 (0)