Skip to content

Commit

Permalink
Systematically change most py::class_ to py::classh under docs/
Browse files Browse the repository at this point in the history
  • Loading branch information
rwgk committed Feb 24, 2025
1 parent 449cceb commit ac9d31e
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 137 deletions.
4 changes: 2 additions & 2 deletions docs/advanced/cast/eigen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ example:
};
// Later, in binding code:
py::class_<MyClass>(m, "MyClass")
py::classh<MyClass>(m, "MyClass")
.def(py::init<>())
.def("copy_matrix", &MyClass::getMatrix) // Makes a copy!
.def("get_matrix", &MyClass::getMatrix, py::return_value_policy::reference_internal)
Expand Down Expand Up @@ -250,7 +250,7 @@ copying to take place:
// The associated binding code:
using namespace pybind11::literals; // for "arg"_a
py::class_<MyClass>(m, "MyClass")
py::classh<MyClass>(m, "MyClass")
// ... other class definitions
.def("some_method", &MyClass::some_method, py::arg().noconvert());
Expand Down
14 changes: 7 additions & 7 deletions docs/advanced/cast/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Overview

.. rubric:: 1. Native type in C++, wrapper in Python

Exposing a custom C++ type using :class:`py::class_` was covered in detail
in the :doc:`/classes` section. There, the underlying data structure is
always the original C++ class while the :class:`py::class_` wrapper provides
a Python interface. Internally, when an object like this is sent from C++ to
Python, pybind11 will just add the outer wrapper layer over the native C++
object. Getting it back from Python is just a matter of peeling off the
wrapper.
Exposing a custom C++ type using ``py::classh`` (or ``py::class_``) was
covered in detail in the :doc:`/classes` section. There, the underlying
data structure is always the original C++ class while the ``py::classh``
wrapper provides a Python interface. Internally, when an object like this
is sent from C++ to Python, pybind11 will just add the outer wrapper layer
over the native C++ object. Getting it back from Python is just a matter of
peeling off the wrapper.

.. rubric:: 2. Wrapper in C++, native type in Python

Expand Down
6 changes: 3 additions & 3 deletions docs/advanced/cast/stl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ functions:
/* ... binding code ... */
py::class_<MyClass>(m, "MyClass")
py::classh<MyClass>(m, "MyClass")
.def(py::init<>())
.def_readwrite("contents", &MyClass::contents);
Expand Down Expand Up @@ -169,12 +169,12 @@ macro must be specified at the top level (and outside of any namespaces), since
it adds a template instantiation of ``type_caster``. If your binding code consists of
multiple compilation units, it must be present in every file (typically via a
common header) preceding any usage of ``std::vector<int>``. Opaque types must
also have a corresponding ``class_`` declaration to associate them with a name
also have a corresponding ``py::classh`` declaration to associate them with a name
in Python, and to define a set of available operations, e.g.:

.. code-block:: cpp
py::class_<std::vector<int>>(m, "IntVector")
py::classh<std::vector<int>>(m, "IntVector")
.def(py::init<>())
.def("clear", &std::vector<int>::clear)
.def("pop_back", &std::vector<int>::pop_back)
Expand Down
Loading

0 comments on commit ac9d31e

Please sign in to comment.