Skip to content

Commit

Permalink
Restore minor general fixes that got lost when ac9d31e was reverted.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwgk committed Mar 1, 2025
1 parent 7dc507e commit 8409b19
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions docs/advanced/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The binding code also needs a few minor adaptations (highlighted):
}
Importantly, pybind11 is made aware of the trampoline helper class by
specifying it as an extra template argument to :class:`class_`. (This can also
specifying it as an extra template argument to ``py::class_``. (This can also
be combined with other template arguments such as a custom holder type; the
order of template types does not matter). Following this, we are able to
define a constructor as usual.
Expand All @@ -139,8 +139,8 @@ classes.
To enable safely passing a ``std::unique_ptr`` to a trampoline object between
Python and C++,

1. the C++ type (``Animal`` above) must be wrapped with ``py::class<..., py::smart_holder>``
(see :ref:`smart_holder`), and
1. the C++ type (``Animal`` above) must be wrapped with
``py::class_<..., py::smart_holder>`` (see :ref:`smart_holder`), and

2. the trampoline helper class must inherit from
``py::trampoline_self_life_support``.
Expand Down Expand Up @@ -984,23 +984,23 @@ because of conflicting definitions on the external type:
// dogs.cpp
// Binding for external library class:
py::class<pets::Pet>(m, "Pet")
py::class_<pets::Pet>(m, "Pet")
.def("name", &pets::Pet::name);
// Binding for local extension class:
py::class<Dog, pets::Pet>(m, "Dog")
py::class_<Dog, pets::Pet>(m, "Dog")
.def(py::init<std::string>());
.. code-block:: cpp
// cats.cpp, in a completely separate project from the above dogs.cpp.
// Binding for external library class:
py::class<pets::Pet>(m, "Pet")
py::class_<pets::Pet>(m, "Pet")
.def("get_name", &pets::Pet::name);
// Binding for local extending class:
py::class<Cat, pets::Pet>(m, "Cat")
py::class_<Cat, pets::Pet>(m, "Cat")
.def(py::init<std::string>());
.. code-block:: pycon
Expand All @@ -1018,13 +1018,13 @@ the ``py::class_`` constructor:
.. code-block:: cpp
// Pet binding in dogs.cpp:
py::class<pets::Pet>(m, "Pet", py::module_local())
py::class_<pets::Pet>(m, "Pet", py::module_local())
.def("name", &pets::Pet::name);
.. code-block:: cpp
// Pet binding in cats.cpp:
py::class<pets::Pet>(m, "Pet", py::module_local())
py::class_<pets::Pet>(m, "Pet", py::module_local())
.def("get_name", &pets::Pet::name);
This makes the Python-side ``dogs.Pet`` and ``cats.Pet`` into distinct classes,
Expand Down Expand Up @@ -1233,7 +1233,7 @@ but once again each instantiation must be explicitly specified:
T fn(V v);
};
py::class<MyClass<int>>(m, "MyClassT")
py::class_<MyClass<int>>(m, "MyClassT")
.def("fn", &MyClass<int>::fn<std::string>);
Custom automatic downcasters
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ from Section :ref:`inheritance`.
Suppose now that ``Pet`` bindings are defined in a module named ``basic``,
whereas the ``Dog`` bindings are defined somewhere else. The challenge is of
course that the variable ``pet`` is not available anymore though it is needed
to indicate the inheritance relationship to the constructor of ``class_<Dog>``.
to indicate the inheritance relationship to the constructor of ``py::class_<Dog>``.
However, it can be acquired as follows:

.. code-block:: cpp
Expand Down
8 changes: 4 additions & 4 deletions docs/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The binding code for ``Pet`` looks as follows:
.def("getName", &Pet::getName);
}
:class:`class_` creates bindings for a C++ *class* or *struct*-style data
``py::class_`` creates bindings for a C++ *class* or *struct*-style data
structure. :func:`init` is a convenience function that takes the types of a
constructor's parameters as template arguments and wraps the corresponding
constructor (see the :ref:`custom_constructors` section for details).
Expand Down Expand Up @@ -265,7 +265,7 @@ inheritance relationship:
There are two different ways of indicating a hierarchical relationship to
pybind11: the first specifies the C++ base class as an extra template
parameter of the :class:`class_`:
parameter of the ``py::class_``:

.. code-block:: cpp
Expand All @@ -279,7 +279,7 @@ parameter of the :class:`class_`:
.def("bark", &Dog::bark);
Alternatively, we can also assign a name to the previously bound ``Pet``
:class:`class_` object and reference it when binding the ``Dog`` class:
``py::class_`` object and reference it when binding the ``Dog`` class:

.. code-block:: cpp
Expand Down Expand Up @@ -505,7 +505,7 @@ The binding code for this example looks as follows:
To ensure that the nested types ``Kind`` and ``Attributes`` are created within the scope of ``Pet``, the
``pet`` :class:`class_` instance must be supplied to the :class:`enum_` and :class:`class_`
``pet`` ``py::class_`` instance must be supplied to the :class:`enum_` and ``py::class_``
constructor. The :func:`enum_::export_values` function exports the enum entries
into the parent scope, which should be skipped for newer C++11-style strongly
typed enums.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Convenience functions converting to Python types
.. _extras:

Passing extra arguments to ``def`` or ``py::class_``
================================================
====================================================

.. doxygengroup:: annotations
:members:
Expand Down

0 comments on commit 8409b19

Please sign in to comment.