Skip to content

Commit e9c2803

Browse files
committed
Fix scan_expression not to mark sequence as Load
1 parent 036f464 commit e9c2803

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

compiler/src/symboltable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ impl SymbolTableBuilder {
585585
}
586586
Bytes { .. } => {}
587587
Tuple { elements } | Set { elements } | List { elements } | Slice { elements } => {
588-
self.scan_expressions(elements, &ExpressionContext::Load)?;
588+
self.scan_expressions(elements, context)?;
589589
}
590590
Comprehension { kind, generators } => {
591591
match **kind {

tests/snippets/comprehensions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,17 @@
2727
w = [x for x, in z]
2828
assert w == [9, 10]
2929

30+
# generator targets shouldn't affect scopes out of comprehensions
31+
[a for a in range(5)]
32+
assert 'a' not in locals()
33+
assert 'a' not in globals()
34+
35+
[b for a, b in [(1, 1), (2, 2)]]
36+
assert 'b' not in locals()
37+
assert 'b' not in globals()
38+
39+
{b: c for b, c in {1: 2}.items()}
40+
assert 'b' not in locals()
41+
assert 'c' not in locals()
42+
assert 'b' not in globals()
43+
assert 'c' not in globals()

0 commit comments

Comments
 (0)