Skip to content

Commit 53a6bc3

Browse files
committed
Add method.__func__ property
1 parent a901323 commit 53a6bc3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

vm/src/obj/objfunction.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,22 @@ impl PyBoundMethod {
298298
))
299299
}
300300

301+
#[pyproperty(magic)]
302+
fn doc(&self, vm: &VirtualMachine) -> PyResult {
303+
vm.get_attribute(self.function.clone(), "__doc__")
304+
}
305+
301306
#[pymethod(magic)]
302-
fn getattribute(&self, name: PyStringRef, vm: &VirtualMachine) -> PyResult {
303-
vm.get_attribute(self.function.clone(), name)
307+
fn getattribute(zelf: PyRef<Self>, name: PyStringRef, vm: &VirtualMachine) -> PyResult {
308+
if let Some(obj) = zelf.class().get_attr(name.as_str()) {
309+
return vm.call_if_get_descriptor(obj, zelf.into_object());
310+
}
311+
vm.get_attribute(zelf.function.clone(), name)
312+
}
313+
314+
#[pyproperty(magic)]
315+
fn func(&self) -> PyObjectRef {
316+
self.function.clone()
304317
}
305318
}
306319

0 commit comments

Comments
 (0)