Skip to content

Commit

Permalink
improve new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed May 18, 2023
1 parent 9f814a4 commit 96f17a8
Showing 1 changed file with 6 additions and 6 deletions.
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

0 comments on commit 96f17a8

Please sign in to comment.