From 868b1afa05c7847e6ffdd1808916719b511b4bcc Mon Sep 17 00:00:00 2001 From: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> Date: Sat, 30 Apr 2022 14:35:33 -0400 Subject: gh-92063: Enforce types in specialized PRECALL opcodes (GH-92068) * Check the types of PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS * fix PRECALL_NO_KW_METHOD_DESCRIPTOR_NOARGS as well * fix PRECALL_NO_KW_METHOD_DESCRIPTOR_O * fix PRECALL_NO_KW_METHOD_DESCRIPTOR_FAST --- Lib/test/test_descr.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'Lib/test/test_descr.py') diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 378ff5227e..48d43d7af8 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4726,6 +4726,33 @@ order (MRO) for bases """ with self.assertRaises(TypeError): str.__add__(fake_str, "abc") + def test_specialized_method_calls_check_types(self): + # https://github.com/python/cpython/issues/92063 + class Thing: + pass + thing = Thing() + for i in range(20): + with self.assertRaises(TypeError): + # PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS + list.sort(thing) + for i in range(20): + with self.assertRaises(TypeError): + # PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS + str.split(thing) + for i in range(20): + with self.assertRaises(TypeError): + # PRECALL_NO_KW_METHOD_DESCRIPTOR_NOARGS + str.upper(thing) + for i in range(20): + with self.assertRaises(TypeError): + # PRECALL_NO_KW_METHOD_DESCRIPTOR_FAST + str.strip(thing) + from collections import deque + for i in range(20): + with self.assertRaises(TypeError): + # PRECALL_NO_KW_METHOD_DESCRIPTOR_O + deque.append(thing, thing) + def test_repr_as_str(self): # Issue #11603: crash or infinite loop when rebinding __str__ as # __repr__. -- cgit v1.2.1