mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
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:
1 parent
49f4771e91
commit
39bee673a9
1 file changed
+3
-7
@@ -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
|
||||
|
||||
Reference in new issue
Block a user