Skip to content

Commit

Permalink
Add a test that confirms __getattr__ doesn't override
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu committed Jul 13, 2019
1 parent 7a83cb6 commit 60cbe2f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_dunder.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 60cbe2f

Please sign in to comment.