diff options
author | Carl Meyer <carl@oddbird.net> | 2024-05-03 14:05:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-03 14:05:19 (GMT) |
commit | c8deb1e4b495bf97ab00c710dfd63f227e1fb645 (patch) | |
tree | 9ee53d752cc465a45c6df665e65ff08c32a253cc /Lib/test/test_listcomps.py | |
parent | 37ccf167869d101c4021c435868b7f89ccda8148 (diff) | |
download | cpython-c8deb1e4b495bf97ab00c710dfd63f227e1fb645.zip cpython-c8deb1e4b495bf97ab00c710dfd63f227e1fb645.tar.gz cpython-c8deb1e4b495bf97ab00c710dfd63f227e1fb645.tar.bz2 |
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>
Diffstat (limited to 'Lib/test/test_listcomps.py')
-rw-r--r-- | Lib/test/test_listcomps.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_listcomps.py b/Lib/test/test_listcomps.py index 2868dd0..df1debf 100644 --- a/Lib/test/test_listcomps.py +++ b/Lib/test/test_listcomps.py @@ -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} |