Skip to content
Prev Previous commit
Next Next commit
a couple more tests
  • Loading branch information
carljm committed May 17, 2023
commit 045478f8979385441a4be0423b84e3548a0cc5f7
13 changes: 13 additions & 0 deletions Lib/test/test_listcomps.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,19 @@ def test_nested_has_free_var(self):
outputs = {"items": [1]}
self._check_in_scopes(code, outputs, scopes=["class"])

def test_nested_free_var_not_bound_in_outer_comp(self):
code = """
z = 1
items = [a for a in [1] if [x for x in [1] if z]]
"""
self._check_in_scopes(code, {"items": [1]}, scopes=["module", "function"])
self._check_in_scopes(code, {"items": []}, ns={"z": 0}, scopes=["class"])

def test_nested_free_var_in_iter(self):
code = """
items = [_C for _C in [1] for [0, 1][[x for x in [1] if _C][0]] in [2]]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we could test here that the name resolution in the inner listcomp here is right. I'll try to come up with some more tests around nested listcomps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you still planning to add more tests here, or improve this one?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will push some more tests today or tomorrow. If you'd prefer to merge this now we can also do that; I can just write more tests in another PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think if we get known fixes merged sooner it's easier to do more effective fuzz testing; if we find more issues we can fix them in separate PRs, and we can add more tests that we think of in separate PRs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added two more tests and turned on automerge.

"""
self._check_in_scopes(code, {"items": [1]})


__test__ = {'doctests' : doctests}
Expand Down