@@ -13,7 +13,7 @@ use crate::{
1313 PyComparisonValue ,
1414 } ,
1515 protocol:: { PyNumber , PyNumberMethods } ,
16- types:: { AsNumber , Comparable , Constructor , Hashable , PyComparisonOp } ,
16+ types:: { AsNumber , Callable , Comparable , Constructor , Hashable , PyComparisonOp } ,
1717 AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyResult ,
1818 TryFromBorrowedObject , TryFromObject , VirtualMachine ,
1919} ;
@@ -481,11 +481,13 @@ impl PyFloat {
481481 Ok ( ( numer, denom) )
482482 }
483483
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+ }
489491 }
490492
491493 #[ pymethod]
0 commit comments