pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

[BUG]: Documentation on static member variables does not carry over

Open srydell opened this issue 3 years ago • 1 comments

Required prerequisites

  • [X] Make sure you've read the documentation. Your issue may be addressed there.
  • [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [X] Consider asking first in the Gitter chat room or in a Discussion.

Problem description

Hi,

First of all, thank you for this amazing library.

I have a small problem. Documentation written on def_readonly_static and def_readwrite_static does not carry over to python. Example:

struct MyStruct {
  static int const i;
  static int j;
}

Initialized in another C++ source file:

int const MyStruct::i = 0;
int Mystruct::j = 0;

And with the pybind11:

PYBIND11_MODULE(m, m) {
  pybind::class_<MyStruct>(m, "MyStruct", "")
    .def_readonly_static("i", &MyStruct::i, "This is not readable from python")
    .def_readwrite_static("j", &MyStruct::j, "This is not readable from python")
}

Reading the documentation string from python results in the help text for the type (in this case int):

>>> import m
>>> print(m.MyStruct.i.__doc__)
int([x]) -> integer
int(x, base=10) -> integer

Convert a number or string to an integer, ...

The same is shown for j. When using a class property that is not static the documentation string is shown instead.

Is it possible to have the documentation for static member variables show in python aswell?

I am using

pybind11 v2.9.0 Linux

Thanks for taking the time.

Reproducible example code

No response

srydell avatar Mar 21 '22 10:03 srydell

+1 to this. This is annoying because I can't properly document the static member using sphinx autodoc. I've tried v2.9.1 and v2.9.2, but the doc string for my static member doesn't seem to exist.

At first, I thought it was my binding code, but I'm beginning to doubt that. @pybind Given the steps outlined to reproduce (which align with my problematic experience), is there really a need for a reproducible example code/project?

2bndy5 avatar May 02 '22 10:05 2bndy5