@@ -23,6 +23,7 @@ pub struct ObTypeLookup {
2323 dict : usize ,
2424 // other numeric types
2525 decimal_object : Py < PyAny > ,
26+ fraction_object : Py < PyAny > ,
2627 // other string types
2728 bytes : usize ,
2829 bytearray : usize ,
@@ -62,14 +63,25 @@ pub enum IsType {
6263
6364impl ObTypeLookup {
6465 fn new ( py : Python ) -> Self {
66+ // todo: delete before PR ready
67+ println ! ( "[RUST] ObTypeLookup::new" ) ;
6568 Self {
6669 none : PyNone :: type_object_raw ( py) as usize ,
6770 int : PyInt :: type_object_raw ( py) as usize ,
6871 bool : PyBool :: type_object_raw ( py) as usize ,
6972 float : PyFloat :: type_object_raw ( py) as usize ,
7073 list : PyList :: type_object_raw ( py) as usize ,
7174 dict : PyDict :: type_object_raw ( py) as usize ,
72- decimal_object : py. import ( "decimal" ) . unwrap ( ) . getattr ( "Decimal" ) . unwrap ( ) . unbind ( ) ,
75+ decimal_object : {
76+ // todo: delete before PR ready
77+ println ! ( "[RUST] ObTypeLookup::new - loading decimal_object" ) ;
78+ py. import ( "decimal" ) . unwrap ( ) . getattr ( "Decimal" ) . unwrap ( ) . unbind ( )
79+ } ,
80+ fraction_object : {
81+ // todo: delete before PR ready
82+ println ! ( "[RUST] ObTypeLookup::new - loading fraction_object" ) ;
83+ py. import ( "fractions" ) . unwrap ( ) . getattr ( "Fraction" ) . unwrap ( ) . unbind ( )
84+ } ,
7385 string : PyString :: type_object_raw ( py) as usize ,
7486 bytes : PyBytes :: type_object_raw ( py) as usize ,
7587 bytearray : PyByteArray :: type_object_raw ( py) as usize ,
@@ -96,6 +108,7 @@ impl ObTypeLookup {
96108 }
97109
98110 pub fn is_type ( & self , value : & Bound < ' _ , PyAny > , expected_ob_type : ObType ) -> IsType {
111+ println ! ( "[RUST] is_type - expected_ob_type: {expected_ob_type}" ) ;
99112 match self . ob_type_is_expected ( Some ( value) , & value. get_type ( ) , & expected_ob_type) {
100113 IsType :: False => {
101114 if expected_ob_type == self . fallback_isinstance ( value) {
@@ -116,6 +129,7 @@ impl ObTypeLookup {
116129 ) -> IsType {
117130 let type_ptr = py_type. as_ptr ( ) ;
118131 let ob_type = type_ptr as usize ;
132+ println ! ( "[RUST] ob_type_is_expected - ob_type: {ob_type}, expected_ob_type: {expected_ob_type}" ) ;
119133 let ans = match expected_ob_type {
120134 ObType :: None => self . none == ob_type,
121135 ObType :: Int => self . int == ob_type,
@@ -137,7 +151,16 @@ impl ObTypeLookup {
137151 ObType :: Str => self . string == ob_type,
138152 ObType :: List => self . list == ob_type,
139153 ObType :: Dict => self . dict == ob_type,
140- ObType :: Decimal => self . decimal_object . as_ptr ( ) as usize == ob_type,
154+ ObType :: Decimal => {
155+ // todo: delete before PR ready
156+ println ! ( "[RUST] ob_type_is_expected - checking ObType::Decimal" ) ;
157+ self . decimal_object . as_ptr ( ) as usize == ob_type
158+ } ,
159+ ObType :: Fraction => {
160+ // todo: delete before PR ready
161+ println ! ( "[RUST] ob_type_is_expected - checking ObType::Fraction" ) ;
162+ self . fraction_object . as_ptr ( ) as usize == ob_type
163+ } ,
141164 ObType :: StrSubclass => self . string == ob_type && op_value. is_none ( ) ,
142165 ObType :: Tuple => self . tuple == ob_type,
143166 ObType :: Set => self . set == ob_type,
@@ -214,7 +237,13 @@ impl ObTypeLookup {
214237 } else if ob_type == self . dict {
215238 ObType :: Dict
216239 } else if ob_type == self . decimal_object . as_ptr ( ) as usize {
240+ // todo: delete before PR ready
241+ println ! ( "[RUST] lookup_by_ob_type - found ObType::Decimal" ) ;
217242 ObType :: Decimal
243+ } else if ob_type == self . fraction_object . as_ptr ( ) as usize {
244+ // todo: delete before PR ready
245+ println ! ( "[RUST] lookup_by_ob_type - found ObType::Fraction" ) ;
246+ ObType :: Fraction
218247 } else if ob_type == self . bytes {
219248 ObType :: Bytes
220249 } else if ob_type == self . tuple {
@@ -322,7 +351,13 @@ impl ObTypeLookup {
322351 } else if value. is_instance_of :: < PyMultiHostUrl > ( ) {
323352 ObType :: MultiHostUrl
324353 } else if value. is_instance ( self . decimal_object . bind ( py) ) . unwrap_or ( false ) {
354+ // todo: delete before PR ready
355+ println ! ( "[RUST] fallback_isinstance - found ObType::Decimal" ) ;
325356 ObType :: Decimal
357+ } else if value. is_instance ( self . fraction_object . bind ( py) ) . unwrap_or ( false ) {
358+ // todo: delete before PR ready
359+ println ! ( "[RUST] fallback_isinstance - found ObType::Fraction" ) ;
360+ ObType :: Fraction
326361 } else if value. is_instance ( self . uuid_object . bind ( py) ) . unwrap_or ( false ) {
327362 ObType :: Uuid
328363 } else if value. is_instance ( self . enum_object . bind ( py) ) . unwrap_or ( false ) {
@@ -380,6 +415,7 @@ pub enum ObType {
380415 Float ,
381416 FloatSubclass ,
382417 Decimal ,
418+ Fraction ,
383419 // string types
384420 Str ,
385421 StrSubclass ,
0 commit comments