Python: Add test

This commit is contained in:
Taus
2023-11-03 22:53:59 +00:00
parent f67c68da9a
commit 75e6de8311
3 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
type_vars_without_bound
| test.py:1:8:1:9 | TypeVar | T1 | TypeAlias T |
| test.py:3:7:3:8 | TypeVar | T6 | Function f |
| test.py:5:9:5:11 | TypeVar | T10 | Class C |
type_vars_with_bound
| test.py:1:12:1:17 | TypeVar | T2 | E1 | TypeAlias T |
| test.py:3:11:3:16 | TypeVar | T7 | E2 | Function f |
| test.py:5:14:5:20 | TypeVar | T11 | E3 | Class C |
type_var_tuples
| test.py:1:20:1:22 | TypeVarTuple | T3 | TypeAlias T |
| test.py:3:19:3:21 | TypeVarTuple | T8 | Function f |
| test.py:5:23:5:26 | TypeVarTuple | T12 | Class C |
param_specs
| test.py:1:25:1:28 | ParamSpec | T4 | TypeAlias T |
| test.py:3:24:3:27 | ParamSpec | T9 | Function f |
| test.py:5:29:5:33 | ParamSpec | T13 | Class C |
type_aliases
| test.py:1:1:1:34 | TypeAlias | T | T5 |

View File

@@ -0,0 +1,5 @@
type T[T1, T2: E1, *T3, **T4] = T5
def f[T6, T7: E2, *T8, **T9](): ...
class C[T10, T11: E3, *T12, **T13]: ...

View File

@@ -0,0 +1,36 @@
import python
string pretty_name(AstNode n) {
result = "Function " + n.(Function).getName()
or
result = "Class " + n.(ClassExpr).getName()
or
result = "TypeAlias " + n.(TypeAlias).getName().getId()
}
query predicate type_vars_without_bound(TypeVar tv, string name, string parent) {
tv.getName().getId() = name and
not exists(tv.getBound()) and
parent = pretty_name(tv.getParent().getParent())
}
query predicate type_vars_with_bound(TypeVar tv, string name, string bound, string parent) {
tv.getName().getId() = name and
bound = tv.getBound().(Name).getId() and
parent = pretty_name(tv.getParent().getParent())
}
query predicate type_var_tuples(TypeVarTuple tvt, string name, string parent) {
tvt.getName().getId() = name and
parent = pretty_name(tvt.getParent().getParent())
}
query predicate param_specs(ParamSpec ps, string name, string parent) {
ps.getName().getId() = name and
parent = pretty_name(ps.getParent().getParent())
}
query predicate type_aliases(TypeAlias ta, string name, string value) {
ta.getName().getId() = name and
value = ta.getValue().(Name).getId()
}