8000 gh-104602: ensure all cellvars are known up front by carljm · Pull Request #104603 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104602: ensure all cellvars are known up front #104603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 19, 2023
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
0