Skip to content

Commit de900fc

Browse files
committed
Python: Add QL test for comprehensions with unpacking
1 parent fc5b356 commit de900fc

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| 3 | ListComp |
2+
| 5 | SetComp |
3+
| 7 | DictComp |
4+
| 9 | GeneratorExp |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# PEP 798: Unpacking in comprehensions
2+
3+
flat_list = [*x for x in nested]
4+
5+
flat_set = {*x for x in nested}
6+
7+
merged = {**d for d in dicts}
8+
9+
gen = (*x for x in nested)
10+
11+
# Force the new parser (the old parser cannot handle lazy imports)
12+
lazy import _pep798_parser_hint
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import python
2+
3+
from Expr e
4+
where
5+
e.getLocation().getFile().getShortName() = "test.py" and
6+
(
7+
e instanceof ListComp or
8+
e instanceof SetComp or
9+
e instanceof DictComp or
10+
e instanceof GeneratorExp
11+
)
12+
select e.getLocation().getStartLine(), e.toString()

0 commit comments

Comments
 (0)