(&'a self, vm: &VirtualMachine)
| 334 | } |
| 335 | |
| 336 | pub fn try_to_primitive<'a, I>(&'a self, vm: &VirtualMachine) -> PyResult<I> |
| 337 | where |
| 338 | I: PrimInt + TryFrom<&'a BigInt>, |
| 339 | { |
| 340 | // TODO: Python 3.14+: ValueError for negative int to unsigned type |
| 341 | // See stdlib_socket.py socket.htonl(-1) |
| 342 | // |
| 343 | // if I::min_value() == I::zero() && self.as_bigint().sign() == Sign::Minus { |
| 344 | // return Err(vm.new_value_error("Cannot convert negative int".to_owned())); |
| 345 | // } |
| 346 | |
| 347 | I::try_from(self.as_bigint()).map_err(|_| { |
| 348 | vm.new_overflow_error(format!( |
| 349 | "Python int too large to convert to Rust {}", |
| 350 | core::any::type_name::<I>() |
| 351 | )) |
| 352 | }) |
| 353 | } |
| 354 | |
| 355 | #[inline] |
| 356 | fn int_op<F>(&self, other: PyObjectRef, op: F) -> PyArithmeticValue<BigInt> |
no test coverage detected