[BUG] Descriptions of static members are not printed via help command
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Issue description
The documentation gives an example about providing description for a definition which can be seen by help.
Static members of a class can be accessed via def_readonly_static and def_readwrite_static.
The problem is that all descriptions are visible with help command except that of static members.
Reproducible example code
include/ClassTest.hpp
#ifndef CLASSTEST_HPP
#define CLASSTEST_HPP
#include <string>
struct ClassTest
{
static std::string static_data;
static std::string print_static_data();
std::string _data;
ClassTest(const std::string& data);
std::string print_data() const;
std::string& change_data(std::string& data);
};
#endif // CLASSTEST_HPP
cpp2py.cpp
#include "ClassTest.hpp"
#include <pybind11/pybind11.h>
namespace py = pybind11;
PYBIND11_MODULE(class_test, m)
{
m.doc() = "pybind11 example class";
py::class_<ClassTest>(m, "ClassTest", "the example class")
.def_readonly ("data_readonly", &ClassTest::_data, "read-only data" )
.def_readwrite("data" , &ClassTest::_data, "read-write data")
.def_readonly_static ("static_data_readonly", &ClassTest::static_data, "static read-only data" )
.def_readwrite_static("static_data" , &ClassTest::static_data, "static read-write data")
.def_static("print_static_data", &ClassTest::print_static_data,
"static method that prints and returns a copy of static_data")
.def(py::init<const std::string &>(), "initialize data")
.def("print_data" , &ClassTest::print_data , "const method that prints data")
.def("change_data", &ClassTest::change_data, "modifier method that returns reference to data");
}
test_class.py
import class_test
help(class_test)
Output:
Help on module class_test:
NAME
class_test - pybind11 example class
CLASSES
pybind11_builtins.pybind11_object(builtins.object)
ClassTest
class ClassTest(pybind11_builtins.pybind11_object)
| the example class
|
| Method resolution order:
| ClassTest
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: class_test.ClassTest, arg0: str) -> None
|
| initialize data
|
| change_data(...)
| change_data(self: class_test.ClassTest, arg0: str) -> str
|
| modifier method that returns reference to data
|
| print_data(...)
| print_data(self: class_test.ClassTest) -> str
|
| const method that prints data
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| print_static_data(...) from builtins.PyCapsule
| print_static_data() -> str
|
| static method that prints and returns a copy of static_data
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| data
| read-write data
|
| data_readonly
| read-only data
|
| static_data
|
| static_data_readonly
|
| ----------------------------------------------------------------------
| Methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) from pybind11_builtins.pybind11_type
| Create and return a new object. See help(type) for accurate signature.
FILE
pybind11_example\class_test.cp36-win_amd64.pyd
Note that descriptions for static_data and static_data_readonly are missing.
pybind11 version: v2.6.2
The other files
src/ClassTest.cpp
#include <iostream>
#include "ClassTest.hpp"
std::string ClassTest::static_data = "static_data";
std::string ClassTest::print_static_data()
{
std::cout << static_data << std::endl;
return static_data;
}
ClassTest::ClassTest(const std::string& data) : _data(data) {}
std::string ClassTest::print_data() const
{
std::cout << _data << std::endl;
return _data;
}
std::string& ClassTest::change_data(std::string& data)
{
_data = data;
return _data;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.4)
project(pybind11example)
set(CMAKE_CXX_STANDARD 11)
include_directories(include)
add_subdirectory(pybind11)
pybind11_add_module(class_test cpp2py.cpp src/ClassTest.cpp)
target_compile_definitions(class_test PRIVATE)
setup.py
from setuptools import setup
setup(name='class_test')
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the missing descriptions with the shown cpp2py.cpp binding and test_class.py help call. Start by tracing def_readonly_static and def_readwrite_static, then compare their generated help output with the instance fields and static method; done means both static member descriptions appear in help.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100