diff options
author | Carl Meyer <carl@oddbird.net> | 2023-05-19 01:50:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-19 01:50:24 (GMT) |
commit | 70c77964778817907fbcc2a047a2abad4eb6e127 (patch) | |
tree | 25d5c17e0acc78dbd0783f344abb63436d38e32c /Lib/test/test_listcomps.py | |
parent | 86e6f16ccb97f66f2b9a31191ce347dca499d48c (diff) | |
download | cpython-70c77964778817907fbcc2a047a2abad4eb6e127.zip cpython-70c77964778817907fbcc2a047a2abad4eb6e127.tar.gz cpython-70c77964778817907fbcc2a047a2abad4eb6e127.tar.bz2 |
gh-104619: never leak comprehension locals to outer locals() (#104637)
Diffstat (limited to 'Lib/test/test_listcomps.py')
-rw-r--r-- | Lib/test/test_listcomps.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_listcomps.py b/Lib/test/test_listcomps.py index fdd2d66..185658a 100644 --- a/Lib/test/test_listcomps.py +++ b/Lib/test/test_listcomps.py @@ -516,6 +516,19 @@ class ListComprehensionTest(unittest.TestCase): """ self._check_in_scopes(code, {"a": [1]}, scopes=["function"]) + def test_no_leakage_to_locals(self): + code = """ + def b(): + [a for b in [1] for _ in []] + return b, locals() + r, s = b() + x = r is b + y = list(s.keys()) + """ + self._check_in_scopes(code, {"x": True, "y": []}, scopes=["module"]) + self._check_in_scopes(code, {"x": True, "y": ["b"]}, scopes=["function"]) + self._check_in_scopes(code, raises=NameError, scopes=["class"]) + __test__ = {'doctests' : doctests} |