Skip to content

Commit 210e8a0

Browse files
authored
Merge pull request RustPython#1830 from youknowone/method-repr
Basic bound method repr
2 parents 7faab46 + d148bdd commit 210e8a0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

vm/src/obj/objfunction.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl PyFunction {
271271
#[derive(Debug)]
272272
pub struct PyBoundMethod {
273273
// TODO: these shouldn't be public
274-
pub object: PyObjectRef,
274+
object: PyObjectRef,
275275
pub function: PyObjectRef,
276276
}
277277

@@ -290,6 +290,14 @@ impl PyBoundMethod {
290290

291291
#[pyimpl(with(SlotCall))]
292292
impl PyBoundMethod {
293+
#[pymethod(magic)]
294+
fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
295+
Ok(format!(
296+
"<bound method of {}>",
297+
vm.to_repr(&self.object)?.as_str()
298+
))
299+
}
300+
293301
#[pymethod(magic)]
294302
fn getattribute(&self, name: PyStringRef, vm: &VirtualMachine) -> PyResult {
295303
vm.get_attribute(self.function.clone(), name)

0 commit comments

Comments
 (0)