property rename via macro

This commit is contained in:
Giles Cope 2020-04-13 07:12:04 +01:00 committed by David Hewitt
parent 2688e26391
commit 08802e2024

View file

@ -44,6 +44,30 @@ macro_rules! fn_macro {
fn_macro!("(a, b=None, *, c=42)", a, b = "None", c = 42);
macro_rules! property_rename_via_macro {
($prop_name:ident) => {
#[pyclass]
struct ClassWithProperty {
member: u64,
}
#[pymethods]
impl ClassWithProperty {
#[getter($prop_name)]
fn get_member(&self) -> u64 {
self.member
}
#[setter($prop_name)]
fn set_member(&mut self, member: u64) {
self.member = member;
}
}
};
}
property_rename_via_macro!(my_new_property_name);
#[test]
fn test_macro_rules_interactions() {
Python::with_gil(|py| {
@ -56,5 +80,12 @@ fn test_macro_rules_interactions() {
my_func,
"my_func.__text_signature__ == '(a, b=None, *, c=42)'"
);
let renamed_prop = py.get_type::<ClassWithProperty>();
py_assert!(
py,
renamed_prop,
"hasattr(renamed_prop, 'my_new_property_name')"
);
});
}