File tree 1 file changed +28
-0
lines changed 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -304,3 +304,31 @@ 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
+ .. _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
+ }
You can’t perform that action at this time.
0 commit comments