mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Return function attributs in method
This commit is contained in:
@@ -33,6 +33,10 @@ class Bar:
|
||||
assert __class__ is Bar
|
||||
return self.x
|
||||
|
||||
def doc_func(self):
|
||||
"doc string"
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def fubar(cls, x):
|
||||
assert __class__ is cls
|
||||
@@ -48,6 +52,8 @@ class Bar:
|
||||
assert Bar.__doc__ == " W00t "
|
||||
|
||||
bar = Bar(42)
|
||||
assert bar.get_x.__doc__ == None
|
||||
assert bar.doc_func.__doc__ == "doc string"
|
||||
|
||||
bar.fubar(2)
|
||||
Bar.fubar(2)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::objcode::PyCodeRef;
|
||||
use super::objdict::PyDictRef;
|
||||
use super::objstr::PyStringRef;
|
||||
use super::objtuple::PyTupleRef;
|
||||
use super::objtype::PyClassRef;
|
||||
use crate::function::PyFuncArgs;
|
||||
@@ -69,6 +70,10 @@ impl PyMethod {
|
||||
pub fn new(object: PyObjectRef, function: PyObjectRef) -> Self {
|
||||
PyMethod { object, function }
|
||||
}
|
||||
|
||||
fn getattribute(&self, name: PyStringRef, vm: &VirtualMachine) -> PyResult {
|
||||
vm.get_attribute(self.function.clone(), name.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl PyValue for PyMethod {
|
||||
@@ -92,6 +97,11 @@ pub fn init(context: &PyContext) {
|
||||
"__get__" => context.new_rustfunc(bind_method),
|
||||
"__call__" => context.new_rustfunc(PyFunctionRef::call),
|
||||
});
|
||||
|
||||
let method_type = &context.types.bound_method_type;
|
||||
extend_class!(context, method_type, {
|
||||
"__getattribute__" => context.new_rustfunc(PyMethod::getattribute),
|
||||
});
|
||||
}
|
||||
|
||||
fn bind_method(
|
||||
|
||||
Reference in New Issue
Block a user