(x: PyObjectRef, vm: &VirtualMachine)
| 365 | |
| 366 | #[pyfunction] |
| 367 | fn ceil(x: PyObjectRef, vm: &VirtualMachine) -> PyResult { |
| 368 | // Only call __ceil__ if the class defines it - if it exists but is not callable, |
| 369 | // the error should be propagated (not fall back to float conversion) |
| 370 | if x.class().has_attr(identifier!(vm, __ceil__)) { |
| 371 | return try_magic_method(identifier!(vm, __ceil__), vm, &x); |
| 372 | } |
| 373 | // __ceil__ not defined - fall back to float conversion |
| 374 | if let Some(v) = x.try_float_opt(vm) { |
| 375 | let v = try_f64_to_bigint(v?.to_f64().ceil(), vm)?; |
| 376 | return Ok(vm.ctx.new_int(v).into()); |
| 377 | } |
| 378 | Err(vm.new_type_error(format!( |
| 379 | "type '{}' doesn't define '__ceil__' method", |
| 380 | x.class().name(), |
| 381 | ))) |
| 382 | } |
| 383 | |
| 384 | #[pyfunction] |
| 385 | fn floor(x: PyObjectRef, vm: &VirtualMachine) -> PyResult { |
nothing calls this directly
no test coverage detected