Skip to content

Commit

Permalink
WIP: failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Sep 26, 2024
1 parent 0268b07 commit 84f2c62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Lib/test/test_listcomps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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=["function"])

__test__ = {'doctests' : doctests}

def load_tests(loader, tests, pattern):
Expand Down
2 changes: 1 addition & 1 deletion Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 84f2c62

Please sign in to comment.