@@ -12,13 +12,42 @@ namespace pydrake {
12
12
/* *
13
13
@page python_bindings Python Bindings
14
14
15
+ # Overview
16
+
15
17
Drake uses [pybind11](http://pybind11.readthedocs.io/en/stable/) for binding
16
18
its C++ API to Python.
17
19
18
20
At present, a fork of `pybind11` is used which permits bindings matrices with
19
21
`dtype=object`, passing `unique_ptr` objects, and prevents aliasing for Python
20
22
classes derived from `pybind11` classes.
21
23
24
+ ## `pybind11` Tips
25
+
26
+ ### Python Types
27
+
28
+ Throughout the Drake code, Python types provided by `pybind11` are used, such
29
+ as `py::handle`, `py::object`, `py::module`, `py::str`, `py::list`, etc.
30
+ For an overview, see the
31
+ [pybind11 reference](http://pybind11.readthedocs.io/en/stable/reference.html).
32
+
33
+ All of these are effectively thin wrappers around `PyObject*`, and thus can be
34
+ cheaply copied.
35
+
36
+ Mutating the referred-to object also does not require passing by reference, so
37
+ you can always pass the object by value for functions, but you should document
38
+ your method if it mutates the object in a non-obvious fashion.
39
+
40
+ ### Python Type Conversions
41
+
42
+ You can implicit convert between `py::object` and its derived classes (such
43
+ as `py::list`, `py::class_`, etc.), assuming the actual Python types agree.
44
+ You may also implicitly convert from `py::object` (and its derived classes) to
45
+ `py::handle`.
46
+
47
+ If you wish to convert a `py::handle` (or `PyObject*`) to `py::object` or a
48
+ derived class, you should use
49
+ [`py::reinterpret_borrow<>`](http://pybind11.readthedocs.io/en/stable/reference.html#_CPPv218reinterpret_borrow6handle).
50
+
22
51
# Conventions
23
52
24
53
## Target Conventions
0 commit comments