summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-11-10 11:50:34 (GMT)
committerGitHub <noreply@github.com>2022-11-10 11:50:34 (GMT)
commit9d692841691590c25e6cf5b2250a594d3bf54825 (patch)
tree82a0948fc0096f8d2e0b9aaa83a86057212582c8 /Lib
parent26726c76494d85c7b565b764c732dd4473458409 (diff)
downloadcpython-9d692841691590c25e6cf5b2250a594d3bf54825.zip
cpython-9d692841691590c25e6cf5b2250a594d3bf54825.tar.gz
cpython-9d692841691590c25e6cf5b2250a594d3bf54825.tar.bz2
GH-99257: Check the owner's type when specializing slots (GH-99258)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_opcache.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/Lib/test/test_opcache.py b/Lib/test/test_opcache.py
index 5c032d5..e39b726 100644
--- a/Lib/test/test_opcache.py
+++ b/Lib/test/test_opcache.py
@@ -177,6 +177,73 @@ class TestLoadAttrCache(unittest.TestCase):
for _ in range(1025):
self.assertFalse(f())
+ def test_load_shadowing_slot_should_raise_type_error(self):
+ class Class:
+ __slots__ = ("slot",)
+
+ class Sneaky:
+ __slots__ = ("shadowed",)
+ shadowing = Class.slot
+
+ def f(o):
+ o.shadowing
+
+ o = Sneaky()
+ o.shadowed = 42
+
+ for _ in range(1025):
+ with self.assertRaises(TypeError):
+ f(o)
+
+ def test_store_shadowing_slot_should_raise_type_error(self):
+ class Class:
+ __slots__ = ("slot",)
+
+ class Sneaky:
+ __slots__ = ("shadowed",)
+ shadowing = Class.slot
+
+ def f(o):
+ o.shadowing = 42
+
+ o = Sneaky()
+
+ for _ in range(1025):
+ with self.assertRaises(TypeError):
+ f(o)
+
+ def test_load_borrowed_slot_should_not_crash(self):
+ class Class:
+ __slots__ = ("slot",)
+
+ class Sneaky:
+ borrowed = Class.slot
+
+ def f(o):
+ o.borrowed
+
+ o = Sneaky()
+
+ for _ in range(1025):
+ with self.assertRaises(TypeError):
+ f(o)
+
+ def test_store_borrowed_slot_should_not_crash(self):
+ class Class:
+ __slots__ = ("slot",)
+
+ class Sneaky:
+ borrowed = Class.slot
+
+ def f(o):
+ o.borrowed = 42
+
+ o = Sneaky()
+
+ for _ in range(1025):
+ with self.assertRaises(TypeError):
+ f(o)
+
class TestLoadMethodCache(unittest.TestCase):
def test_descriptor_added_after_optimization(self):