Skip to content
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

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

Merged
merged 5 commits into from
May 19, 2023
Merged
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
improve new tests
  • Loading branch information
carljm committed May 18, 2023
commit 96f17a85a66761504be410b654582bcc712f1dad
12 changes: 6 additions & 6 deletions Lib/test/test_listcomps.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,25 +385,25 @@ def test_global_outside_cellvar_inside_plus_freevar(self):
code = """
a = 1
def f():
[(lambda: b) for b in [a]]
return b
func, = [(lambda: b) for b in [a]]
return b, func()
x = f()
"""
self._check_in_scopes(
code, {"x": 2}, ns={"b": 2}, scopes=["function", "module"])
code, {"x": (2, 1)}, 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
(func, inner_b), = [[lambda: b for b in c] + [b] for c in [[a]]]
return b, inner_b, func()
x = f()
"""
self._check_in_scopes(
code, {"x": 2}, ns={"b": 2}, scopes=["function", "module"])
code, {"x": (2, 2, 1)}, 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"])

Expand Down