@@ -398,7 +398,7 @@ impl PyType {
398398 )
399399 }
400400 #[ pyslot]
401- fn tp_new ( metatype : PyTypeRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
401+ fn tp_new ( metatype : PyTypeRef , mut args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
402402 vm_trace ! ( "type.__new__ {:?}" , args) ;
403403
404404 let is_type_type = metatype. is ( & vm. ctx . types . type_type ) ;
@@ -439,8 +439,8 @@ impl PyType {
439439 #[ allow( clippy:: redundant_clone) ] // false positive
440440 if let Some ( ref tp_new) = winner. clone ( ) . slots . new {
441441 // Pass it to the winner
442-
443- return tp_new ( vm, args. insert ( winner . into_object ( ) ) ) ;
442+ args . prepend_arg ( winner . into_object ( ) ) ;
443+ return tp_new ( vm, args) ;
444444 }
445445 winner
446446 } else {
@@ -694,18 +694,20 @@ impl<T: DerefToPyType> DerefToPyType for &'_ T {
694694fn call_tp_new (
695695 typ : PyTypeRef ,
696696 subtype : PyTypeRef ,
697- args : FuncArgs ,
697+ mut args : FuncArgs ,
698698 vm : & VirtualMachine ,
699699) -> PyResult {
700700 for cls in typ. deref ( ) . iter_mro ( ) {
701701 if let Some ( new_meth) = cls. get_attr ( "__new__" ) {
702702 if !vm. ctx . is_tp_new_wrapper ( & new_meth) {
703703 let new_meth = vm. call_if_get_descriptor ( new_meth, typ. clone ( ) . into_object ( ) ) ?;
704- return vm. invoke ( & new_meth, args. insert ( typ. clone ( ) . into_object ( ) ) ) ;
704+ args. prepend_arg ( typ. clone ( ) . into_object ( ) ) ;
705+ return vm. invoke ( & new_meth, args) ;
705706 }
706707 }
707708 if let Some ( tp_new) = cls. slots . new . as_ref ( ) {
708- return tp_new ( vm, args. insert ( subtype. into_object ( ) ) ) ;
709+ args. prepend_arg ( subtype. into_object ( ) ) ;
710+ return tp_new ( vm, args) ;
709711 }
710712 }
711713 unreachable ! ( "Should be able to find a new slot somewhere in the mro" )
0 commit comments