mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Merge pull request #1830 from youknowone/method-repr
Basic bound method repr
This commit is contained in:
1 file changed
+9
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user