[3.12] gh-105340: include hidden fast-locals in locals() (GH-105715) (#106470)

gh-105340: include hidden fast-locals in locals() (GH-105715)

* gh-105340: include hidden fast-locals in locals()
(cherry picked from commit 104d7b760f)

Co-authored-by: Carl Meyer <carl@oddbird.net>
This commit is contained in:
Miss Islington (bot) 2023-07-05 16:31:37 -07:00 committed by GitHub
parent a49a29f22b
commit bb17e6f5de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 160 additions and 44 deletions

View file

@ -539,6 +539,28 @@ class ListComprehensionTest(unittest.TestCase):
self._check_in_scopes(code, {"x": True, "y": ["b"]}, scopes=["function"])
self._check_in_scopes(code, raises=NameError, scopes=["class"])
def test_iter_var_available_in_locals(self):
code = """
l = [1, 2]
y = 0
items = [locals()["x"] for x in l]
items2 = [vars()["x"] for x in l]
items3 = [("x" in dir()) for x in l]
items4 = [eval("x") for x in l]
# x is available, and does not overwrite y
[exec("y = x") for x in l]
"""
self._check_in_scopes(
code,
{
"items": [1, 2],
"items2": [1, 2],
"items3": [True, True],
"items4": [1, 2],
"y": 0
}
)
__test__ = {'doctests' : doctests}