8000 gh-104374: Remove access to class scopes for inlined comprehensions by JelleZijlstra · Pull Request #104528 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104374: Remove access to class scopes for inlined comprehensions #104528

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 10 commits into from
May 18, 2023
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
8000
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
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
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
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
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
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
0