diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-06-10 04:37:28 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-10 04:37:28 (GMT) |
| commit | 03cd44759f8e5faaa154628e196860255d87bddd (patch) | |
| tree | 1722f2ad13b2a1305dd6e2abd78571d4b27e7f4a /Lib/test/test_listcomps.py | |
| parent | c15f94d6fbc960790db34c94d49716658ccf6348 (diff) | |
| download | cpython-03cd44759f8e5faaa154628e196860255d87bddd.zip cpython-03cd44759f8e5faaa154628e196860255d87bddd.tar.gz cpython-03cd44759f8e5faaa154628e196860255d87bddd.tar.bz2 | |
[3.13] gh-119666: fix multiple class-scope comprehensions referencing __class__ (GH-120295) (#120299)
Diffstat (limited to 'Lib/test/test_listcomps.py')
| -rw-r--r-- | Lib/test/test_listcomps.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_listcomps.py b/Lib/test/test_listcomps.py index ec2aac8..58b076e 100644 --- a/Lib/test/test_listcomps.py +++ b/Lib/test/test_listcomps.py @@ -168,6 +168,31 @@ class ListComprehensionTest(unittest.TestCase): """ self._check_in_scopes(code, raises=NameError) + def test_references___class___defined(self): + code = """ + __class__ = 2 + res = [__class__ for x in [1]] + """ + self._check_in_scopes( + code, outputs={"res": [2]}, scopes=["module", "function"]) + self._check_in_scopes(code, raises=NameError, scopes=["class"]) + + def test_references___class___enclosing(self): + code = """ + __class__ = 2 + class C: + res = [__class__ for x in [1]] + res = C.res + """ + self._check_in_scopes(code, raises=NameError) + + def test_super_and_class_cell_in_sibling_comps(self): + code = """ + [super for _ in [1]] + [__class__ for _ 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)] |
