MCPcopy Create free account
hub / github.com/PyO3/pyo3 / instance_method

Function instance_method

tests/test_methods.rs:36–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34
35#[test]
36fn instance_method() {
37 Python::attach(|py| {
38 let obj = Bound::new(py, InstanceMethod { member: 42 }).unwrap();
39 let obj_ref = obj.borrow();
40 assert_eq!(obj_ref.method(), 42);
41 py_assert!(py, obj, "obj.method() == 42");
42 py_assert!(py, obj, "obj.add_other(obj) == 84");
43 py_assert!(py, obj, "obj.method.__doc__ == 'Test method'");
44 });
45}
46
47/// Test that CPython's method-wrapper descriptor rejects wrong receiver types
48/// when `tp_methods` entries are called with a bad `self` from Python.

Callers

nothing calls this directly

Calls 1

borrowMethod · 0.45

Tested by

no test coverage detected