@@ -29,12 +29,6 @@ pub struct PyComplex {
2929 value : Complex64 ,
3030}
3131
32- impl PyComplex {
33- pub const fn to_complex64 ( self ) -> Complex64 {
34- self . value
35- }
36- }
37-
3832impl PyPayload for PyComplex {
3933 #[ inline]
4034 fn class ( ctx : & Context ) -> & ' static Py < PyType > {
@@ -234,13 +228,30 @@ impl Constructor for PyComplex {
234228}
235229
236230impl PyComplex {
231+ #[ deprecated( note = "use PyComplex::from(...).into_ref() instead" ) ]
237232 pub fn new_ref ( value : Complex64 , ctx : & Context ) -> PyRef < Self > {
238- PyRef :: new_ref ( Self :: from ( value) , ctx. types . complex_type . to_owned ( ) , None )
233+ Self :: from ( value) . into_ref ( ctx)
234+ }
235+
236+ pub const fn to_complex64 ( self ) -> Complex64 {
237+ self . value
239238 }
240239
241240 pub const fn to_complex ( & self ) -> Complex64 {
242241 self . value
243242 }
243+
244+ fn number_op < F , R > ( a : & PyObject , b : & PyObject , op : F , vm : & VirtualMachine ) -> PyResult
245+ where
246+ F : FnOnce ( Complex64 , Complex64 , & VirtualMachine ) -> R ,
247+ R : ToPyResult ,
248+ {
249+ if let ( Some ( a) , Some ( b) ) = ( to_op_complex ( a, vm) ?, to_op_complex ( b, vm) ?) {
250+ op ( a, b, vm) . to_pyresult ( vm)
251+ } else {
252+ Ok ( vm. ctx . not_implemented ( ) )
253+ }
254+ }
244255}
245256
246257#[ pyclass(
@@ -503,20 +514,6 @@ impl Representable for PyComplex {
503514 }
504515}
505516
506- impl PyComplex {
507- fn number_op < F , R > ( a : & PyObject , b : & PyObject , op : F , vm : & VirtualMachine ) -> PyResult
508- where
509- F : FnOnce ( Complex64 , Complex64 , & VirtualMachine ) -> R ,
510- R : ToPyResult ,
511- {
512- if let ( Some ( a) , Some ( b) ) = ( to_op_complex ( a, vm) ?, to_op_complex ( b, vm) ?) {
513- op ( a, b, vm) . to_pyresult ( vm)
514- } else {
515- Ok ( vm. ctx . not_implemented ( ) )
516- }
517- }
518- }
519-
520517#[ derive( FromArgs ) ]
521518pub struct ComplexArgs {
522519 #[ pyarg( any, optional) ]
0 commit comments