@@ -2,17 +2,15 @@ use super::dict::{PyDict, PyDictRef};
22use super :: list:: PyList ;
33use super :: pybool;
44use super :: pystr:: { PyStr , PyStrRef } ;
5- use super :: pytype:: PyTypeRef ;
6- use crate :: builtins:: pytype;
7- use crate :: builtins:: pytype:: PyType ;
5+ use super :: pytype:: { PyType , PyTypeRef } ;
86use crate :: common:: hash:: PyHash ;
97use crate :: function:: FuncArgs ;
108use crate :: slots:: PyComparisonOp ;
119use crate :: utils:: Either ;
1210use crate :: vm:: VirtualMachine ;
1311use crate :: {
1412 IdProtocol , ItemProtocol , PyArithmaticValue , PyAttributes , PyClassImpl , PyComparisonValue ,
15- PyContext , PyObject , PyObjectRef , PyResult , PyValue , TypeProtocol ,
13+ PyContext , PyObject , PyObjectRef , PyRef , PyResult , PyValue , TypeProtocol ,
1614} ;
1715
1816/// object()
@@ -34,11 +32,6 @@ impl PyValue for PyBaseObject {
3432
3533#[ pyimpl( flags( BASETYPE ) ) ]
3634impl PyBaseObject {
37- #[ pyclassmethod( magic) ]
38- fn new ( cls : PyTypeRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
39- let ( subtype, args) : ( PyTypeRef , FuncArgs ) = args. bind ( vm) ?;
40- pytype:: call_tp_new ( cls, subtype, args, vm)
41- }
4235 /// Create and return a new object. See help(type) for accurate signature.
4336 #[ pyslot]
4437 fn tp_new ( cls : PyTypeRef , _args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
@@ -370,8 +363,19 @@ pub(crate) fn setattr(
370363 }
371364}
372365
373- pub fn init ( context : & PyContext ) {
374- PyBaseObject :: extend_class ( context, & context. types . object_type ) ;
366+ pub fn init ( ctx : & PyContext ) {
367+ PyBaseObject :: extend_class ( ctx, & ctx. types . object_type ) ;
368+ let class = & ctx. types . object_type ;
369+
370+ let new_str = "__new__" ;
371+ let tp_new_wrapper = PyRef :: new_ref (
372+ ctx. make_funcdef ( new_str, PyType :: __new__) . into_function ( ) ,
373+ ctx. types . builtin_function_or_method_type . clone ( ) ,
374+ None ,
375+ )
376+ . into_object ( ) ;
377+ let bound = ctx. new_bound_method ( tp_new_wrapper, class. clone ( ) . into_object ( ) ) ;
378+ class. set_str_attr ( new_str, bound) ;
375379}
376380
377381fn common_reduce ( obj : PyObjectRef , proto : usize , vm : & VirtualMachine ) -> PyResult {
0 commit comments