mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Preserve float-subclass values in time.sleep conversion (#9292)
Follow CPython PyFloat_AsDouble without calling float-subclass overrides. Keep index precedence and other conversion behavior unchanged. Assisted-by: OpenAI Codex
This commit is contained in:
1 parent
39bee673a9
commit
308085dafc
1 file changed
+6
-2
@@ -19,7 +19,7 @@ mod decl {
|
||||
use crate::convert::{ToPyException, ToPyObject};
|
||||
use crate::{
|
||||
AsObject, Py, PyObjectRef, PyResult, VirtualMachine,
|
||||
builtins::{PyStr, PyStrRef, PyTypeRef},
|
||||
builtins::{PyFloat, PyStr, PyStrRef, PyTypeRef},
|
||||
class::PyClassDef,
|
||||
common::wtf8::Wtf8Buf,
|
||||
function::{Either, FuncArgs, OptionalArg, OptionalOption},
|
||||
@@ -143,7 +143,11 @@ mod decl {
|
||||
.and_then(|seconds| seconds.checked_mul(SEC_TO_NS))
|
||||
.ok_or_else(overflow)?
|
||||
} else {
|
||||
let seconds = object.try_float(vm)?.to_f64();
|
||||
// PyFloat_AsDouble reads float subclasses without calling __float__.
|
||||
let seconds = match object.downcast_ref::<PyFloat>() {
|
||||
Some(value) => value.to_f64(),
|
||||
None => object.try_float(vm)?.to_f64(),
|
||||
};
|
||||
if seconds.is_nan() {
|
||||
return Err(vm.new_value_error("Invalid value NaN (not a number)"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user