Skip to content

Commit 8c18208

Browse files
Update vm/src/builtins/float.rs
Co-authored-by: Snowapril <sinjihng@gmail.com>
1 parent 8960e78 commit 8c18208

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

vm/src/builtins/float.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,10 @@ impl PyFloat {
483483

484484
#[pyclassmethod]
485485
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-
}
486+
let result = float_ops::from_hex(string.as_str().trim()).ok_or_else(|| {
487+
vm.new_value_error("invalid hexadecimal floating-point string".to_owned())
488+
})?;
489+
PyType::call(&cls, vec![vm.ctx.new_float(result).into()].into(), vm)
491490
}
492491

493492
#[pymethod]

0 commit comments

Comments
 (0)