@@ -13,7 +13,7 @@ use crate::{
13
13
PyComparisonValue ,
14
14
} ,
15
15
protocol:: { PyNumber , PyNumberMethods } ,
16
- types:: { AsNumber , Comparable , Constructor , Hashable , PyComparisonOp } ,
16
+ types:: { AsNumber , Callable , Comparable , Constructor , Hashable , PyComparisonOp } ,
17
17
AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyResult ,
18
18
TryFromBorrowedObject , TryFromObject , VirtualMachine ,
19
19
} ;
@@ -481,11 +481,13 @@ impl PyFloat {
481
481
Ok ( ( numer, denom) )
482
482
}
483
483
484
- #[ pymethod]
485
- fn fromhex ( repr : PyStrRef , vm : & VirtualMachine ) -> PyResult < f64 > {
486
- float_ops:: from_hex ( repr. as_str ( ) . trim ( ) ) . ok_or_else ( || {
487
- vm. new_value_error ( "invalid hexadecimal floating-point string" . to_owned ( ) )
488
- } )
484
+ #[ pyclassmethod]
485
+ fn fromhex ( cls : PyTypeRef , string : PyStrRef , vm : & VirtualMachine ) -> PyResult {
486
+ let result = float_ops:: from_hex ( string. as_str ( ) . trim ( ) ) ;
487
+ match result {
488
+ Some ( value) => PyType :: call ( & cls, vec ! [ vm. ctx. new_float( value) . into( ) ] . into ( ) , vm) ,
489
+ None => Err ( vm. new_value_error ( "invalid hexadecimal floating-point string" . to_owned ( ) ) ) ,
490
+ }
489
491
}
490
492
491
493
#[ pymethod]
0 commit comments