summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2024-06-01 04:56:26 (GMT)
committerGitHub <noreply@github.com>2024-06-01 04:56:26 (GMT)
commita0559849ac2de604ffa410268be262a8482ad23c (patch)
tree15a9f8e6e74955545903761ea8275a084e437ba4 /Lib
parent0a266f7e74ce1ff4ad6e88f05473cc6a22ab7e20 (diff)
downloadcpython-a0559849ac2de604ffa410268be262a8482ad23c.zip
cpython-a0559849ac2de604ffa410268be262a8482ad23c.tar.gz
cpython-a0559849ac2de604ffa410268be262a8482ad23c.tar.bz2
[3.13] gh-119821: Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS (#119822) (#119889)
dSupport non-dict globals in LOAD_FROM_DICT_OR_GLOBALS The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated, but that seems like it may get hairy since the two operations have different operands. This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too, and we should backport to 3.13 and 3.12 if possible. (cherry picked from commit 80a4e3899420faaa012c82b4e82cdb6675a6a944)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_type_aliases.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_type_aliases.py b/Lib/test/test_type_aliases.py
index 9c325bc..f8b395f 100644
--- a/Lib/test/test_type_aliases.py
+++ b/Lib/test/test_type_aliases.py
@@ -1,4 +1,5 @@
import pickle
+import textwrap
import types
import unittest
from test.support import check_syntax_error, run_code
@@ -328,3 +329,22 @@ class TypeAliasPickleTest(unittest.TestCase):
with self.subTest(thing=thing, proto=proto):
with self.assertRaises(pickle.PickleError):
pickle.dumps(thing, protocol=proto)
+
+
+class TypeParamsExoticGlobalsTest(unittest.TestCase):
+ def test_exec_with_unusual_globals(self):
+ class customdict(dict):
+ def __missing__(self, key):
+ return key
+
+ code = compile("type Alias = undefined", "test", "exec")
+ ns = customdict()
+ exec(code, ns)
+ Alias = ns["Alias"]
+ self.assertEqual(Alias.__value__, "undefined")
+
+ code = compile("class A: type Alias = undefined", "test", "exec")
+ ns = customdict()
+ exec(code, ns)
+ Alias = ns["A"].Alias
+ self.assertEqual(Alias.__value__, "undefined")