From e053914a0df026f32bc2fb15d92cee0a144813b8 Mon Sep 17 00:00:00 2001 From: Jiseok CHOI Date: Fri, 8 Aug 2025 14:25:29 +0900 Subject: [PATCH] Implement type check in member descriptor `__set__` --- Lib/test/test_opcache.py | 2 -- vm/src/builtins/descriptor.rs | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_opcache.py b/Lib/test/test_opcache.py index 8f1f8764b1..fad3cd2dbe 100644 --- a/Lib/test/test_opcache.py +++ b/Lib/test/test_opcache.py @@ -197,8 +197,6 @@ def f(o): with self.assertRaises(TypeError): f(o) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_store_shadowing_slot_should_raise_type_error(self): class Class: __slots__ = ("slot",) diff --git a/vm/src/builtins/descriptor.rs b/vm/src/builtins/descriptor.rs index 2f4d2169bd..977a442529 100644 --- a/vm/src/builtins/descriptor.rs +++ b/vm/src/builtins/descriptor.rs @@ -274,6 +274,16 @@ impl PyMemberDescriptor { vm: &VirtualMachine, ) -> PyResult<()> { let zelf = Self::_as_pyref(zelf, vm)?; + + if !obj.class().fast_issubclass(&zelf.common.typ) { + return Err(vm.new_type_error(format!( + "descriptor '{}' for '{}' objects doesn't apply to a '{}' object", + zelf.common.name, + zelf.common.typ.name(), + obj.class().name() + ))); + } + zelf.member.set(obj, value, vm) } }