(cls: PyTypeRef, number: PyObjectRef, vm: &VirtualMachine)
| 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] |
nothing calls this directly
no test coverage detected