From 88f61fa2182c7dbab8cad7ef67b896c65fdda1d8 Mon Sep 17 00:00:00 2001 From: Lee Dogeon Date: Fri, 13 Feb 2026 21:38:31 +0900 Subject: [PATCH] Fix object.__init__ excess-arg checks for heap types --- Lib/test/test_class.py | 1 - Lib/test/test_descr.py | 1 - crates/vm/src/builtins/object.rs | 9 +++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index e0756b25a5..7420f289b1 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -741,7 +741,6 @@ def __setattr__(self, name, value) -> None: with self.assertRaisesRegex(AttributeError, error_msg): del B().z - @unittest.expectedFailure # TODO: RUSTPYTHON def testConstructorErrorMessages(self): # bpo-31506: Improves the error message logic for object_new & object_init diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index fc38a482ef..0d46129793 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1853,7 +1853,6 @@ class C(list): __new__ = object.__new__ self.assertRaises(TypeError, C) - @unittest.expectedFailure # TODO: RUSTPYTHON def test_object_new(self): class A(object): pass diff --git a/crates/vm/src/builtins/object.rs b/crates/vm/src/builtins/object.rs index eb9d226acb..e4c5106168 100644 --- a/crates/vm/src/builtins/object.rs +++ b/crates/vm/src/builtins/object.rs @@ -138,11 +138,12 @@ impl Initializer for PyBaseObject { )); } - let typ_new = typ.slots.new.load().map(|f| f as usize); - let object_new = object_type.slots.new.load().map(|f| f as usize); - // if (type->tp_new == object_new) → second error - if typ_new == object_new { + if let (Some(typ_new), Some(object_new)) = ( + typ.get_attr(identifier!(vm, __new__)), + object_type.get_attr(identifier!(vm, __new__)), + ) && typ_new.is(&object_new) + { return Err(vm.new_type_error(format!( "{}.__init__() takes exactly one argument (the instance to initialize)", typ.name()