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.
This commit is contained in:
youknowdot authored and GitHub committed 2026-10-22 14:08:03 +09:00
1 parent 49f4771e91
commit 39bee673a9
1 file changed
+3 -7
+3 -7
View File
@@ -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