sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
232 stars 47 forks source link

def_property_readonly_static broke inspect.getmembers(self.klass) #94

Closed nyaoouo closed 1 year ago

nyaoouo commented 1 year ago

reoroduce cpp module

#include <pybind11/pybind11.h>

struct s {
};

PYBIND11_MODULE(demo, m) {
    pybind11::class_<s>(m, "s")
            .def(pybind11::init<>())
            .def_property_readonly_static("a", []() { return 1; });
}

traceback:

Traceback (most recent call last):
  File "...\pybind11_stubgen\__init__.py", line 1143, in main
    _module.parse()
  File "...\pybind11_stubgen\__init__.py", line 913, in parse
    x.parse()
  File "...\pybind11_stubgen\__init__.py", line 720, in parse
    for name, member in inspect.getmembers(self.klass):
  File ...\Python311\Lib\inspect.py", line 469, in getmembers
    value = getattr(object, key)
TypeError: (): incompatible function arguments. The following argument types are supported:
    1. () -> int

Invoked with: <class 'demo.s'>
nyaoouo commented 1 year ago

solved by change to .def_property_readonly_static("a", [](const pybind11::object&) { return 1; });