Skip to content

Commit a22833d

Browse files
committed
doc: avoid C++ types in docstrings
1 parent 1abc4a9 commit a22833d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/advanced/misc.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,31 @@ the default settings are restored to prevent unwanted side effects.
304304

305305
.. [#f4] http://www.sphinx-doc.org
306306
.. [#f5] http://github.com/pybind/python_example
307+
308+
.. _avoid-cpp-types-in-docstrings:
309+
310+
Avoid C++ types in docstrings
311+
=============================
312+
313+
Most of docstrings are generated at the time of the declaration, e.g. when ``.def(...)`` is called.
314+
At this point arguments/return types should be known to pybind11, otherwise C++ types would be used instead:
315+
316+
.. code-block:: text
317+
318+
| __init__(...)
319+
| __init__(self: example.Foo, arg0: ns::Bar) -> None
320+
^^^^^^^
321+
322+
323+
This limitation can be tolerated by "forward declaring" bound classes:
324+
325+
.. code-block:: cpp
326+
327+
PYBIND11_MODULE(example, m) {
328+
329+
auto pyFoo = py::class_<ns::Foo>(m, "Foo");
330+
auto pyBar = py::class_<ns::Bar>(m, "Bar");
331+
332+
pyFoo.def(py::init<const ns::Bar&>());
333+
pyBar.def(py::init<const ns::Foo&>());
334+
}

0 commit comments

Comments
 (0)