Add a test that confirms __getattr__ doesn't override
This commit is contained in:
parent
7a83cb6afa
commit
60cbe2f47d
22
tests/test_dunder.rs
Normal file → Executable file
22
tests/test_dunder.rs
Normal file → Executable file
|
@ -462,3 +462,25 @@ fn weakref_dunder_dict_support() {
|
|||
"import weakref; assert weakref.ref(inst)() is inst; inst.a = 1; assert inst.a == 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[pyclass]
|
||||
struct ClassWithGetAttr {
|
||||
#[pyo3(get, set)]
|
||||
data: u32,
|
||||
}
|
||||
|
||||
#[pyproto]
|
||||
impl PyObjectProtocol for ClassWithGetAttr {
|
||||
fn __getattr__(&self, _name: &str) -> PyResult<u32> {
|
||||
Ok(self.data * 2)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getattr_doesnt_override_member() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
let inst = PyRef::new(py, ClassWithGetAttr { data: 4 }).unwrap();
|
||||
py_assert!(py, inst, "inst.data == 4");
|
||||
py_assert!(py, inst, "inst.a == 8");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue