mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-104619: never leak comprehension locals to outer locals() (#104637)
This commit is contained in:
parent
86e6f16ccb
commit
70c7796477
2 changed files with 32 additions and 21 deletions
|
@ -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}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue