Skip to content

Incorrect type names in docstrings for nested types #1166

@jondreads

Description

@jondreads

Issue description

I have an inner enum. The type name for the enum in docstrings is not correct. I'm not sure if this is a bug in docstring generation, but I can't see any documentation on how to supply the correct name.

Reproducible example code

#include <pybind11/pybind11.h>
namespace py = pybind11;
struct Pet
{
  enum class Kind { Dog };
  Pet() : type(Kind::Dog) {}
  Kind type;
};
void foo(Pet::Kind) {}
PYBIND11_MODULE (hello, m)
{
  py::class_<Pet> pet(m, "Pet");
  pet.def(py::init())
    .def_readwrite("type", &Pet::type);
  py::enum_<Pet::Kind>(pet, "Kind")
    .value("Dog", Pet::Kind::Dog);
  m.def("foo", &foo);
}

In python

>>> import hello
>>> hello.foo.__doc__
'foo(arg0: hello.Kind) -> None\n'
>>> help(hello.Pet.Kind)
Help on class Kind in module hello:
class Kind(pybind11_builtins.pybind11_object)
...
 |  __eq__(...)
 |      __eq__(self: hello.Kind, arg0: hello.Kind) -> bool
...

I would expect to see "hello.Pet.Kind" in the docstrings not "hello.Kind"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions