pybind / pybind/pybind11

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

Open
#3,815 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Required prerequisites
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior through def_readonly_static and def_readwrite_static using the C++ and Python examples in the issue. Trace how the supplied documentation strings are handled for static versus non-static class properties, and consider the issue done when Python exposes the specified strings through doc for both members.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.