From 308085dafcfd1f83bbb7cb99c8cfbd2edbeceb6a Mon Sep 17 00:00:00 2001 From: youknowdot Date: Wed, 21 Oct 2026 22:50:34 -0700 Subject: [PATCH] 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 --- crates/vm/src/stdlib/time.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/vm/src/stdlib/time.rs b/crates/vm/src/stdlib/time.rs index 02288ca45..b645c1ab7 100644 --- a/crates/vm/src/stdlib/time.rs +++ b/crates/vm/src/stdlib/time.rs @@ -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::() { + 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)")); }