@@ -9,6 +9,7 @@ use num_traits::{One, Pow, Signed, ToPrimitive, Zero};
99use super :: objbool:: IntoPyBool ;
1010use super :: objbytearray:: PyByteArray ;
1111use super :: objbytes:: PyBytes ;
12+ use super :: objdict:: PyDictRef ;
1213use super :: objfloat;
1314use super :: objmemory:: PyMemoryView ;
1415use super :: objstr:: { PyString , PyStringRef } ;
@@ -17,9 +18,8 @@ use crate::bytesinner::PyBytesInner;
1718use crate :: format:: FormatSpec ;
1819use crate :: function:: { OptionalArg , PyFuncArgs } ;
1920use crate :: pyobject:: {
20- IdProtocol , IntoPyObject , IntoPyRef , IntoPyResult , PyArithmaticValue , PyClassImpl ,
21- PyComparisonValue , PyContext , PyObjectRef , PyRef , PyResult , PyValue , TryFromObject ,
22- TypeProtocol ,
21+ IdProtocol , IntoPyObject , IntoPyResult , PyArithmaticValue , PyClassImpl , PyComparisonValue ,
22+ PyContext , PyObject , PyObjectRef , PyRef , PyResult , PyValue , TryFromObject , TypeProtocol ,
2323} ;
2424use crate :: stdlib:: array:: PyArray ;
2525use crate :: vm:: VirtualMachine ;
@@ -78,6 +78,23 @@ impl PyValue for PyInt {
7878 fn class ( vm : & VirtualMachine ) -> PyClassRef {
7979 vm. ctx . int_type ( )
8080 }
81+
82+ fn into_simple_object ( self , vm : & VirtualMachine ) -> PyObjectRef {
83+ vm. ctx . new_int ( self . value )
84+ }
85+
86+ fn into_object (
87+ self ,
88+ vm : & VirtualMachine ,
89+ cls : PyClassRef ,
90+ dict : Option < PyDictRef > ,
91+ ) -> PyObjectRef {
92+ if cls. is ( & Self :: class ( vm) ) {
93+ vm. ctx . new_int ( self . value )
94+ } else {
95+ PyObject :: new ( self , cls, dict)
96+ }
97+ }
8198}
8299
83100macro_rules! impl_into_pyobject_int {
@@ -223,10 +240,10 @@ fn inner_truediv(i1: &BigInt, i2: &BigInt, vm: &VirtualMachine) -> PyResult {
223240impl PyInt {
224241 fn with_value < T > ( cls : PyClassRef , value : T , vm : & VirtualMachine ) -> PyResult < PyIntRef >
225242 where
226- T : Into < BigInt > ,
243+ T : Into < BigInt > + ToPrimitive ,
227244 {
228245 if cls. is ( & vm. ctx . int_type ( ) ) {
229- Ok ( value . into ( ) . into_pyref ( vm ) )
246+ Ok ( PyRef :: from_obj_unchecked ( vm . ctx . new_int ( value ) ) )
230247 } else {
231248 PyInt :: from ( value) . into_ref_with_type ( vm, cls)
232249 }
0 commit comments