MCPcopy Index your code
hub / github.com/RustPython/RustPython / with_value

Method with_value

crates/vm/src/builtins/int.rs:293–304  ·  view source on GitHub ↗
(cls: PyTypeRef, value: T, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

291
292impl 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

Callers

nothing calls this directly

Calls 6

isMethod · 0.80
upcastMethod · 0.80
into_ref_with_typeMethod · 0.80
new_intMethod · 0.45
new_boolMethod · 0.45
eqMethod · 0.45

Tested by

no test coverage detected