diff --git a/crates/vm/src/builtins/builtin_func.rs b/crates/vm/src/builtins/builtin_func.rs index 917b7b24f..5f0991fef 100644 --- a/crates/vm/src/builtins/builtin_func.rs +++ b/crates/vm/src/builtins/builtin_func.rs @@ -195,13 +195,9 @@ impl PyNativeFunction { // meth_get__self__ in CPython #[pygetset] fn __self__(zelf: NativeFunctionOrMethod, vm: &VirtualMachine) -> PyObjectRef { - if let Some(bound) = &zelf.0.zelf { - return bound.clone(); - } - if let Some(module) = &zelf.0.module_object { - return module.clone(); - } - vm.ctx.none() + zelf.0 + .get_self() + .map_or_else(|| vm.ctx.none(), ToOwned::to_owned) } // meth_reduce: the name when unbound or bound to a module, otherwise