From 39bee673a9f080a618a73bc8192529c39d81fa9a Mon Sep 17 00:00:00 2001 From: youknowdot Date: Wed, 21 Oct 2026 22:08:03 -0700 Subject: [PATCH] Respect static-method binding in builtin __self__ (#9291) Reuse get_self() so static builtin methods expose None rather than their stored class receiver, while preserving bound and module receivers. --- crates/vm/src/builtins/builtin_func.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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