File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -528,6 +528,27 @@ def test_symtable_entry_repr(self):
528
528
self .assertEqual (repr (self .top ._table ), expected )
529
529
530
530
531
+ class ComprehensionTests (unittest .TestCase ):
532
+ def get_identifiers_recursive (self , st , res ):
533
+ res .extend (st .get_identifiers ())
534
+ for ch in st .get_children ():
535
+ self .get_identifiers_recursive (ch , res )
536
+
537
+ def test_loopvar_in_only_one_scope (self ):
538
+ # ensure that the loop variable appears only once in the symtable
539
+ comps = [
540
+ "[x for x in [1]]" ,
541
+ "{x for x in [1]}" ,
542
+ "{x:x*x for x in [1]}" ,
543
+ ]
544
+ for comp in comps :
545
+ with self .subTest (comp = comp ):
546
+ st = symtable .symtable (comp , "?" , "exec" )
547
+ ids = []
548
+ self .get_identifiers_recursive (st , ids )
549
+ self .assertEqual (len ([x for x in ids if x == 'x' ]), 1 )
550
+
551
+
531
552
class CommandLineTest (unittest .TestCase ):
532
553
maxDiff = None
533
554
You can’t perform that action at this time.
0 commit comments