Skip to content

Commit 128b159

Browse files
fix bad merge
1 parent 50efd4b commit 128b159

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Lib/test/test_symtable.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,27 @@ def test__symtable_refleak(self):
535535
self.assertRaises(TypeError, symtable.symtable, '', mortal_str, 1)
536536

537537

538+
class ComprehensionTests(unittest.TestCase):
539+
def get_identifiers_recursive(self, st, res):
540+
res.extend(st.get_identifiers())
541+
for ch in st.get_children():
542+
self.get_identifiers_recursive(ch, res)
543+
544+
def test_loopvar_in_only_one_scope(self):
545+
# ensure that the loop variable appears only once in the symtable
546+
comps = [
547+
"[x for x in [1]]",
548+
"{x for x in [1]}",
549+
"{x:x*x for x in [1]}",
550+
]
551+
for comp in comps:
552+
with self.subTest(comp=comp):
553+
st = symtable.symtable(comp, "?", "exec")
554+
ids = []
555+
self.get_identifiers_recursive(st, ids)
556+
self.assertEqual(len([x for x in ids if x == 'x']), 1)
557+
558+
538559
class CommandLineTest(unittest.TestCase):
539560
maxDiff = None
540561

0 commit comments

Comments
 (0)