Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add another test and propagate DEF_COMP_CELL
  • Loading branch information
carljm committed May 18, 2023
commit 9f814a4dc1018955be751b7797bfe20fdb706dc2
15 changes: 15 additions & 0 deletions Lib/test/test_listcomps.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,21 @@ def f():
"""
self._check_in_scopes(
code, {"x": 2}, ns={"b": 2}, scopes=["function", "module"])
# inside a class, the `a = 1` assignment is not visible
self._check_in_scopes(code, raises=NameError, scopes=["class"])

def test_cell_in_nested_comprehension(self):
code = """
a = 1
def f():
[[lambda: b for b in c] + [b] for c in [[a]]]
return b
x = f()
"""
self._check_in_scopes(
code, {"x": 2}, ns={"b": 2}, scopes=["function", "module"])
# inside a class, the `a = 1` assignment is not visible
self._check_in_scopes(code, raises=NameError, scopes=["class"])

def test_name_error_in_class_scope(self):
code = """
Expand Down
2 changes: 1 addition & 1 deletion Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
}
int scope = (comp_flags >> SCOPE_OFFSET) & SCOPE_MASK;
int only_flags = comp_flags & ((1 << SCOPE_OFFSET) - 1);
if (scope == CELL) {
if (scope == CELL || only_flags & DEF_COMP_CELL) {
if (PySet_Add(inlined_cells, k) < 0) {
return 0;
}
Expand Down