diff options
author | Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> | 2022-04-17 18:04:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-17 18:04:29 (GMT) |
commit | cec5d858f509ea28a5325b75fd94e2f275866f5f (patch) | |
tree | fd1a12cd8c374b3eddca3f5ef1baaff98fefd217 /Lib | |
parent | 7659681556977fe3a19d9f4c5dd93362b9eae25c (diff) | |
download | cpython-cec5d858f509ea28a5325b75fd94e2f275866f5f.zip cpython-cec5d858f509ea28a5325b75fd94e2f275866f5f.tar.gz cpython-cec5d858f509ea28a5325b75fd94e2f275866f5f.tar.bz2 |
gh-91625: Don't ignore extended args of adaptive opcodes (GH-91626)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_descr.py | 18 | ||||
-rw-r--r-- | Lib/test/test_dynamic.py | 12 | ||||
-rw-r--r-- | Lib/test/test_unpack.py | 16 |
3 files changed, 44 insertions, 2 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 5d36cb9..378ff52 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1961,6 +1961,20 @@ order (MRO) for bases """ del a[0:10] self.assertEqual(a.delitem, (slice(0, 10))) + def test_load_attr_extended_arg(self): + # https://github.com/python/cpython/issues/91625 + class Numbers: + def __getattr__(self, attr): + return int(attr.lstrip("_")) + attrs = ", ".join(f"Z._{n:03d}" for n in range(280)) + code = f"def number_attrs(Z):\n return [ {attrs} ]" + ns = {} + exec(code, ns) + number_attrs = ns["number_attrs"] + # Warm up the the function for quickening (PEP 659) + for _ in range(30): + self.assertEqual(number_attrs(Numbers()), list(range(280))) + def test_methods(self): # Testing methods... class C(object): @@ -4435,8 +4449,8 @@ order (MRO) for bases """ raise RuntimeError(f"Premature access to sys.stdout.{attr}") with redirect_stdout(StdoutGuard()): - with self.assertRaises(RuntimeError): - print("Oops!") + with self.assertRaises(RuntimeError): + print("Oops!") def test_vicious_descriptor_nonsense(self): # Testing vicious_descriptor_nonsense... diff --git a/Lib/test/test_dynamic.py b/Lib/test/test_dynamic.py index 3ae090f..3e0fcf4 100644 --- a/Lib/test/test_dynamic.py +++ b/Lib/test/test_dynamic.py @@ -133,6 +133,18 @@ class RebindBuiltinsTests(unittest.TestCase): self.assertEqual(foo(), 7) + def test_load_global_specialization_failure_keeps_oparg(self): + # https://github.com/python/cpython/issues/91625 + class MyGlobals(dict): + def __missing__(self, key): + return int(key.removeprefix("_number_")) + + code = "lambda: " + "+".join(f"_number_{i}" for i in range(1000)) + sum_1000 = eval(code, MyGlobals()) + expected = sum(range(1000)) + # Warm up the the function for quickening (PEP 659) + for _ in range(30): + self.assertEqual(sum_1000(), expected) if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_unpack.py b/Lib/test/test_unpack.py index 472c834..f5ca1d4 100644 --- a/Lib/test/test_unpack.py +++ b/Lib/test/test_unpack.py @@ -151,5 +151,21 @@ def load_tests(loader, tests, pattern): return tests +class TestCornerCases(unittest.TestCase): + def test_extended_oparg_not_ignored(self): + # https://github.com/python/cpython/issues/91625 + target = "(" + "y,"*400 + ")" + code = f"""def unpack_400(x): + {target} = x + return y + """ + ns = {} + exec(code, ns) + unpack_400 = ns["unpack_400"] + # Warm up the the function for quickening (PEP 659) + for _ in range(30): + y = unpack_400(range(400)) + self.assertEqual(y, 399) + if __name__ == "__main__": unittest.main() |