From 3f4f068c7fc9ec354937a2474fd0b5d4371b63b8 Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Sun, 14 Apr 2019 00:23:59 +0200 Subject: [PATCH] Ensure `#[getter]` doc is exposed as the `__doc__` of the descriptor --- src/class/methods.rs | 3 +++ tests/test_getter_setter.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/class/methods.rs b/src/class/methods.rs index ea2c2c34..362f78bc 100644 --- a/src/class/methods.rs +++ b/src/class/methods.rs @@ -97,6 +97,9 @@ impl PyGetterDef { .expect("Method name must not contain NULL byte") .into_raw(); } + if dst.doc.is_null() { + dst.doc = self.doc.as_ptr() as *mut libc::c_char; + } dst.get = Some(self.meth); } } diff --git a/tests/test_getter_setter.rs b/tests/test_getter_setter.rs index 7eede5be..ee5057af 100644 --- a/tests/test_getter_setter.rs +++ b/tests/test_getter_setter.rs @@ -1,4 +1,5 @@ use pyo3::prelude::*; +use pyo3::types::IntoPyDict; use std::isize; #[macro_use] @@ -16,6 +17,7 @@ impl ClassWithProperties { } #[getter(DATA)] + /// a getter for data fn get_data(&self) -> PyResult { Ok(self.num) } @@ -38,6 +40,9 @@ fn class_with_properties() { py_run!(py, inst, "inst.DATA = 20"); py_run!(py, inst, "assert inst.get_num() == 20"); py_run!(py, inst, "assert inst.get_num() == inst.DATA"); + + let d = [("C", py.get_type::())].into_py_dict(py); + py.run("assert C.DATA.__doc__ == 'a getter for data'", None, Some(d)).unwrap(); } #[pyclass]