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)")); }