From 2beaa75d9ece62be0bc807285928603cd5ba5e9b Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Wed, 25 Sep 2024 17:02:53 -0700 Subject: [PATCH] WIP: failing test --- Lib/test/test_listcomps.py | 13 +++++++++++++ Python/symtable.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_listcomps.py b/Lib/test/test_listcomps.py index 45644d6c0927827..2f2973d44e3ce45 100644 --- a/Lib/test/test_listcomps.py +++ b/Lib/test/test_listcomps.py @@ -114,6 +114,7 @@ def get_output(moddict, name): def _f(): {code} return locals() + import dis; dis.dis(_f) # TODO _out = _f() """).format(code=textwrap.indent(code, " ")) def get_output(moddict, name): @@ -750,6 +751,18 @@ def iter_raises(): self.assertEqual(f.line[f.colno - indent : f.end_colno - indent], expected) + def test_freevar_through_scope_containing_comprehension(self): + code = """ + x = 1 + def f(): + [x for x in [1]] + def g(): + return x + return g() + y = f() + """ + self._check_in_scopes(code, {"x": 1, "y": 1}, scopes=["module"]) # TODO , "function"]) + __test__ = {'doctests' : doctests} def load_tests(loader, tests, pattern): diff --git a/Python/symtable.c b/Python/symtable.c index 8bc9db6d7d68116..98ea7c59b4c66fa 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -1220,7 +1220,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, // we inline all non-generator-expression comprehensions, // except those in annotation scopes that are nested in classes - int inline_comp = + int inline_comp = true && entry->ste_comprehension && !entry->ste_generator && !ste->ste_can_see_class_scope;