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

Method try_from_object

crates/vm/src/builtins/builtin_func.rs:274–284  ·  view source on GitHub ↗
(vm: &VirtualMachine, obj: PyObjectRef)

Source from the content-addressed store, hash-verified

272
273impl TryFromObject for NativeFunctionOrMethod {
274 fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
275 let class = vm.ctx.types.builtin_function_or_method_type;
276 if obj.fast_isinstance(class) {
277 // Both PyNativeFunction and PyNativeMethod share the same type now.
278 // PyNativeMethod has `func: PyNativeFunction` as its first field,
279 // so we can safely treat the data pointer as PyNativeFunction for reading.
280 Ok(Self(unsafe { obj.downcast_unchecked() }))
281 } else {
282 Err(vm.new_downcast_type_error(class, &obj))
283 }
284 }
285}

Callers

nothing calls this directly

Calls 5

SelfFunction · 0.85
fast_isinstanceMethod · 0.80
downcast_uncheckedMethod · 0.80
ErrClass · 0.50

Tested by

no test coverage detected