Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add GetDescriptor for PyBoundMethod (return self)
CPython's method_descr_get always returns the bound method unchanged.
This preserves the original binding when __get__ is called on an
already-bound method (e.g. a.meth.__get__(b, B) still returns a).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
  • Loading branch information
moreal and claude committed Mar 20, 2026
commit 333af80f44f04526e47b558b85e20481eab49f7f
1 change: 0 additions & 1 deletion Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5130,7 +5130,6 @@ class Child(Parent):
gc.collect()
self.assertEqual(Parent.__subclasses__(), [])

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_instance_method_get_behavior(self):
# test case for gh-113157

Expand Down
21 changes: 20 additions & 1 deletion crates/vm/src/builtins/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,17 @@ impl GetAttr for PyBoundMethod {
}
}

impl GetDescriptor for PyBoundMethod {
fn descr_get(
zelf: PyObjectRef,
_obj: Option<PyObjectRef>,
_cls: Option<PyObjectRef>,
_vm: &VirtualMachine,
) -> PyResult {
Ok(zelf)
}
}

#[derive(FromArgs)]
pub struct PyBoundMethodNewArgs {
#[pyarg(positional)]
Expand Down Expand Up @@ -1258,7 +1269,15 @@ impl PyBoundMethod {
}

#[pyclass(
with(Callable, Comparable, Hashable, GetAttr, Constructor, Representable),
with(
Callable,
Comparable,
Hashable,
GetAttr,
GetDescriptor,
Constructor,
Representable
),
flags(IMMUTABLETYPE, HAS_WEAKREF)
)]
impl PyBoundMethod {
Expand Down