@@ -650,7 +650,10 @@ mod _sqlite {
650650
651651 #[ pyfunction]
652652 fn connect ( args : ConnectArgs , vm : & VirtualMachine ) -> PyResult {
653- Connection :: py_new ( args. factory . clone ( ) , args, vm)
653+ let factory = args. factory . clone ( ) ;
654+ Connection :: py_new ( & factory, args, vm)
655+ . and_then ( |conn| conn. into_ref_with_type ( vm, factory) )
656+ . map ( Into :: into)
654657 }
655658
656659 #[ pyfunction]
@@ -851,12 +854,12 @@ mod _sqlite {
851854 impl Constructor for Connection {
852855 type Args = ConnectArgs ;
853856
854- fn py_new ( cls : PyTypeRef , args : Self :: Args , vm : & VirtualMachine ) -> PyResult {
857+ fn py_new ( cls : & Py < PyType > , args : Self :: Args , vm : & VirtualMachine ) -> PyResult < Self > {
855858 let text_factory = PyStr :: class ( & vm. ctx ) . to_owned ( ) . into_object ( ) ;
856859
857860 // For non-subclassed Connection, initialize in __new__
858861 // For subclassed Connection, leave db as None and require __init__ to be called
859- let is_base_class = cls. is ( Connection :: class ( & vm. ctx ) . as_object ( ) ) ;
862+ let is_base_class = cls. is ( Connection :: class ( & vm. ctx ) ) ;
860863
861864 let db = if is_base_class {
862865 // Initialize immediately for base class
@@ -879,7 +882,7 @@ mod _sqlite {
879882 text_factory : PyAtomicRef :: from ( text_factory) ,
880883 } ;
881884
882- Ok ( conn. into_ref_with_type ( vm , cls ) ? . into ( ) )
885+ Ok ( conn)
883886 }
884887 }
885888
@@ -1940,10 +1943,8 @@ mod _sqlite {
19401943 impl Constructor for Cursor {
19411944 type Args = ( PyRef < Connection > , ) ;
19421945
1943- fn py_new ( cls : PyTypeRef , args : Self :: Args , vm : & VirtualMachine ) -> PyResult {
1944- Self :: new_uninitialized ( args. 0 , vm)
1945- . into_ref_with_type ( vm, cls)
1946- . map ( Into :: into)
1946+ fn py_new ( _cls : & Py < PyType > , args : Self :: Args , vm : & VirtualMachine ) -> PyResult < Self > {
1947+ Ok ( Self :: new_uninitialized ( args. 0 , vm) )
19471948 }
19481949 }
19491950
@@ -2109,20 +2110,18 @@ mod _sqlite {
21092110 impl Constructor for Row {
21102111 type Args = ( PyRef < Cursor > , PyTupleRef ) ;
21112112
2112- fn py_new ( cls : PyTypeRef , args : Self :: Args , vm : & VirtualMachine ) -> PyResult {
2113+ fn py_new ( _cls : & Py < PyType > , args : Self :: Args , vm : & VirtualMachine ) -> PyResult < Self > {
21132114 let description = args
21142115 . 0
21152116 . inner ( vm) ?
21162117 . description
21172118 . clone ( )
21182119 . ok_or_else ( || vm. new_value_error ( "no description in Cursor" ) ) ?;
21192120
2120- Self {
2121+ Ok ( Self {
21212122 data : args. 1 ,
21222123 description,
2123- }
2124- . into_ref_with_type ( vm, cls)
2125- . map ( Into :: into)
2124+ } )
21262125 }
21272126 }
21282127
0 commit comments