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

Method from_number

crates/vm/src/builtins/complex.rs:376–395  ·  view source on GitHub ↗
(cls: PyTypeRef, number: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

374
375 #[pyclassmethod]
376 fn from_number(cls: PyTypeRef, number: PyObjectRef, vm: &VirtualMachine) -> PyResult {
377 if number.class().is(vm.ctx.types.complex_type) && cls.is(vm.ctx.types.complex_type) {
378 return Ok(number);
379 }
380 let value = number
381 .try_complex(vm)?
382 .ok_or_else(|| {
383 vm.new_type_error(format!(
384 "must be real number, not {}",
385 number.class().name()
386 ))
387 })?
388 .0;
389 let result = vm.ctx.new_complex(value);
390 if cls.is(vm.ctx.types.complex_type) {
391 Ok(result.into())
392 } else {
393 PyType::call(&cls, vec![result.into()].into(), vm)
394 }
395 }
396}
397
398#[pyclass]

Callers

nothing calls this directly

Calls 6

isMethod · 0.80
ok_or_elseMethod · 0.80
try_complexMethod · 0.80
callFunction · 0.50
classMethod · 0.45
new_complexMethod · 0.45

Tested by

no test coverage detected