Skip to content

Commit 5de8527

Browse files
authored
Merge pull request RustPython#2312 from qingshi163/array-float
Fix array with float
2 parents 8cdbccd + eaf4bad commit 5de8527

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

vm/src/stdlib/array.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::builtins::bytes::PyBytesRef;
2-
use crate::builtins::float::try_float;
2+
use crate::builtins::float::IntoPyFloat;
33
use crate::builtins::list::PyList;
44
use crate::builtins::memory::{Buffer, BufferOptions, ResizeGuard};
55
use crate::builtins::pystr::PyStrRef;
@@ -449,14 +449,11 @@ fn f64_swap_bytes(x: f64) -> f64 {
449449
}
450450

451451
fn f32_try_into_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<f32> {
452-
try_float(&obj, vm)?
453-
.map(|x| x as f32)
454-
.ok_or_else(|| vm.new_type_error(format!("must be real number, not {}", obj.class().name)))
452+
IntoPyFloat::try_from_object(vm, obj).map(|x| x.to_f64() as f32)
455453
}
456454

457455
fn f64_try_into_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<f64> {
458-
try_float(&obj, vm)?
459-
.ok_or_else(|| vm.new_type_error(format!("must be real number, not {}", obj.class().name)))
456+
IntoPyFloat::try_from_object(vm, obj).map(|x| x.to_f64())
460457
}
461458

462459
#[pyclass(module = "array", name = "array")]

0 commit comments

Comments
 (0)