gh-128396: Fix a crash when inline comprehension has the same local variable as the outside scope (#130235)

This commit is contained in:
Tian Gao 2025-02-19 12:11:17 -05:00 committed by GitHub
parent 5f00501a94
commit ccf17323c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View file

@ -346,6 +346,12 @@ class TestFrameLocals(unittest.TestCase):
self.assertEqual(x, 2)
self.assertEqual(y, 3)
def test_closure_with_inline_comprehension(self):
lambda: k
k = 1
lst = [locals() for k in [0]]
self.assertEqual(lst[0]['k'], 0)
def test_as_dict(self):
x = 1
y = 2