We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8960e78 commit 8c18208Copy full SHA for 8c18208
vm/src/builtins/float.rs
@@ -483,11 +483,10 @@ impl PyFloat {
483
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
- }
+ let result = float_ops::from_hex(string.as_str().trim()).ok_or_else(|| {
+ vm.new_value_error("invalid hexadecimal floating-point string".to_owned())
+ })?;
+ PyType::call(&cls, vec![vm.ctx.new_float(result).into()].into(), vm)
491
}
492
493
#[pymethod]
0 commit comments