Merge pull request #1830 from youknowone/method-repr

Basic bound method repr
This commit is contained in:
Jeong YunWon authored and GitHub committed 2020-03-30 21:58:00 +09:00
commit 210e8a07f0
1 file changed
+9 -1
+9 -1
View File
@@ -271,7 +271,7 @@ impl PyFunction {
#[derive(Debug)]
pub struct PyBoundMethod {
// TODO: these shouldn't be public
pub object: PyObjectRef,
object: PyObjectRef,
pub function: PyObjectRef,
}
@@ -290,6 +290,14 @@ impl PyBoundMethod {
#[pyimpl(with(SlotCall))]
impl PyBoundMethod {
#[pymethod(magic)]
fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
Ok(format!(
"<bound method of {}>",
vm.to_repr(&self.object)?.as_str()
))
}
#[pymethod(magic)]
fn getattribute(&self, name: PyStringRef, vm: &VirtualMachine) -> PyResult {
vm.get_attribute(self.function.clone(), name)