gh-114828: Fix __class__ in class-scope inlined comprehensions (#115139)

This commit is contained in:
Carl Meyer 2024-02-07 11:56:16 -05:00 committed by GitHub
parent 8a3c499ffe
commit fedbf77191
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 0 deletions

View file

@ -156,6 +156,18 @@ class ListComprehensionTest(unittest.TestCase):
self.assertEqual(C.y, [4, 4, 4, 4, 4])
self.assertIs(C().method(), C)
def test_references_super(self):
code = """
res = [super for x in [1]]
"""
self._check_in_scopes(code, outputs={"res": [super]})
def test_references___class__(self):
code = """
res = [__class__ for x in [1]]
"""
self._check_in_scopes(code, raises=NameError)
def test_inner_cell_shadows_outer(self):
code = """
items = [(lambda: i) for i in range(5)]