File tree 1 file changed +31
-0
lines changed 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -304,3 +304,34 @@ the default settings are restored to prevent unwanted side effects.
304
304
305
305
.. [#f4 ] http://www.sphinx-doc.org
306
306
.. [#f5 ] http://github.com/pybind/python_example
307
+
308
+ .. _avoiding-cpp-types-in-docstrings :
309
+
310
+ Avoiding C++ types in docstrings
311
+ ================================
312
+
313
+ Docstrings are generated at the time of the declaration, e.g. when ``.def(...) `` is called.
314
+ At this point parameter and return types should be known to pybind11.
315
+ If a custom type is not exposed yet through a ``py::class_ `` constructor or a custom type caster,
316
+ its C++ type name will be used instead to generate the signature in the docstring:
317
+
318
+ .. code-block :: text
319
+
320
+ | __init__(...)
321
+ | __init__(self: example.Foo, arg0: ns::Bar) -> None
322
+ ^^^^^^^
323
+
324
+
325
+ This limitation can be circumvented by ensuring that C++ classes are registered with pybind11
326
+ before they are used as a parameter or return type of a function:
327
+
328
+ .. code-block :: cpp
329
+
330
+ PYBIND11_MODULE(example, m) {
331
+
332
+ auto pyFoo = py::class_<ns::Foo>(m, "Foo");
333
+ auto pyBar = py::class_<ns::Bar>(m, "Bar");
334
+
335
+ pyFoo.def(py::init<const ns::Bar&>());
336
+ pyBar.def(py::init<const ns::Foo&>());
337
+ }
You can’t perform that action at this time.
0 commit comments