diff options
author | Carl Meyer <carl@oddbird.net> | 2023-05-11 01:08:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-11 01:08:40 (GMT) |
commit | fcd5fb49b1d71165f3c503c3d2e74a082ddb2f21 (patch) | |
tree | b806e49c3b5bb80f82c9b5a32d5c3ee916efc6d2 /Lib/test/test_listcomps.py | |
parent | 94f30c75576bb8a20724b2ac758fa33af089a522 (diff) | |
download | cpython-fcd5fb49b1d71165f3c503c3d2e74a082ddb2f21.zip cpython-fcd5fb49b1d71165f3c503c3d2e74a082ddb2f21.tar.gz cpython-fcd5fb49b1d71165f3c503c3d2e74a082ddb2f21.tar.bz2 |
gh-104357: fix inlined comprehensions that close over iteration var (#104368)
Diffstat (limited to 'Lib/test/test_listcomps.py')
-rw-r--r-- | Lib/test/test_listcomps.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_listcomps.py b/Lib/test/test_listcomps.py index 92fed98..1cc202b 100644 --- a/Lib/test/test_listcomps.py +++ b/Lib/test/test_listcomps.py @@ -163,6 +163,16 @@ class ListComprehensionTest(unittest.TestCase): outputs = {"y": [4, 4, 4, 4, 4], "i": 20} self._check_in_scopes(code, outputs) + def test_inner_cell_shadows_outer_no_store(self): + code = """ + def f(x): + return [lambda: x for x in range(x)], x + fns, x = f(2) + y = [fn() for fn in fns] + """ + outputs = {"y": [1, 1], "x": 2} + self._check_in_scopes(code, outputs) + def test_closure_can_jump_over_comp_scope(self): code = """ items = [(lambda: y) for i in range(5)] |