mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix object.__init__ excess-arg checks for heap types (#7116)
This commit is contained in:
1 parent
856cd558d2
commit
f92a7dd9ca
3 files changed
+5
-6
No files matched your search
Vendored
-1
@@ -741,7 +741,6 @@ class ClassTests(unittest.TestCase):
|
||||
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
|
||||
|
||||
|
||||
Vendored
-1
@@ -1853,7 +1853,6 @@ class ClassPropertiesAndMethods(unittest.TestCase):
|
||||
__new__ = object.__new__
|
||||
self.assertRaises(TypeError, C)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_object_new(self):
|
||||
class A(object):
|
||||
pass
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user