(cls: PyTypeRef, value: T, vm: &VirtualMachine)
| 291 | |
| 292 | impl PyInt { |
| 293 | fn with_value<T>(cls: PyTypeRef, value: T, vm: &VirtualMachine) -> PyResult<PyRef<Self>> |
| 294 | where |
| 295 | T: Into<BigInt> + ToPrimitive, |
| 296 | { |
| 297 | if cls.is(vm.ctx.types.int_type) { |
| 298 | Ok(vm.ctx.new_int(value)) |
| 299 | } else if cls.is(vm.ctx.types.bool_type) { |
| 300 | Ok(vm.ctx.new_bool(!value.into().eq(&BigInt::zero())).upcast()) |
| 301 | } else { |
| 302 | Self::from(value).into_ref_with_type(vm, cls) |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | pub const fn as_bigint(&self) -> &BigInt { |
| 307 | &self.value |