mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
gh-118513: Fix sibling comprehensions with a name bound in one and global in the other (#118526)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
This commit is contained in:
parent
37ccf16786
commit
c8deb1e4b4
3 changed files with 57 additions and 39 deletions
|
@ -666,6 +666,20 @@ class ListComprehensionTest(unittest.TestCase):
|
|||
self._check_in_scopes(code, expected)
|
||||
self._check_in_scopes(code, expected, exec_func=self._replacing_exec)
|
||||
|
||||
def test_multiple_comprehension_name_reuse(self):
|
||||
code = """
|
||||
[x for x in [1]]
|
||||
y = [x for _ in [1]]
|
||||
"""
|
||||
self._check_in_scopes(code, {"y": [3]}, ns={"x": 3})
|
||||
|
||||
code = """
|
||||
x = 2
|
||||
[x for x in [1]]
|
||||
y = [x for _ in [1]]
|
||||
"""
|
||||
self._check_in_scopes(code, {"x": 2, "y": [3]}, ns={"x": 3}, scopes=["class"])
|
||||
self._check_in_scopes(code, {"x": 2, "y": [2]}, ns={"x": 3}, scopes=["function", "module"])
|
||||
|
||||
__test__ = {'doctests' : doctests}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue