mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
[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:
parent
a49a29f22b
commit
bb17e6f5de
8 changed files with 160 additions and 44 deletions
|
@ -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}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue