general cleanup of the codebase
- new pybind11::base<> attribute to indicate a subclass relationship
- unified infrastructure for parsing variadic arguments in class_ and cpp_function
- use 'handle' and 'object' more consistently everywhere
diff --git a/docs/advanced.rst b/docs/advanced.rst
index 4c2b23b..4683c70 100644
--- a/docs/advanced.rst
+++ b/docs/advanced.rst
@@ -925,7 +925,7 @@
FUNCTIONS
...
| myFunction(...)
- | Signature : (MyClass, arg : SomeType = <SomeType object at 0x101b7b080>) -> None
+ | Signature : (MyClass, arg : SomeType = <SomeType object at 0x101b7b080>) -> NoneType
...
The first way of addressing this is by defining ``SomeType.__repr__``.
diff --git a/docs/changelog.rst b/docs/changelog.rst
index b992303..d497e26 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -5,15 +5,19 @@
1.2 (not yet released)
--------------------------
+
* Optional: efficient generation of function signatures at compile time using C++14
-* Switched to a simpler and more general way of dealing with function default arguments
- Unused keyword arguments in function calls are now detected and cause errors as expected
+* Switched to a simpler and more general way of dealing with function default
+ arguments. Unused keyword arguments in function calls are now detected and
+ cause errors as expected
* New ``keep_alive`` call policy analogous to Boost.Python's ``with_custodian_and_ward``
+* New ``pybind11::base<>`` attribute to indicate a subclass relationship
* Improved interface for RAII type wrappers in ``pytypes.h``
* Use RAII type wrappers consistently within pybind11 itself. This
fixes various potential refcount leaks when exceptions occur
* Added new ``bytes`` RAII type wrapper (maps to ``string`` in Python 2.7).
-* Made handle and related RAII classes const correct
+* Made handle and related RAII classes const correct, using them more
+ consistently everywhere now
* Got rid of the ugly ``__pybind11__`` attributes on the Python side---they are
now stored in a C++ hash table that is not visible in Python
* Fixed refcount leaks involving NumPy arrays and bound functions
@@ -21,7 +25,9 @@
* Removed an unnecessary copy operation in ``pybind11::vectorize``
* Fixed naming clashes when both pybind11 and NumPy headers are included
* Added conversions for additional exception types
-* Documentation improvements (using multiple extension modules, smart pointers, other minor clarifications)
+* Documentation improvements (using multiple extension modules, smart pointers,
+ other minor clarifications)
+* unified infrastructure for parsing variadic arguments in class_ and cpp_function
* Fixed license text (was: ZLIB, should have been: 3-clause BSD)
* Python 3.2 compatibility
diff --git a/docs/classes.rst b/docs/classes.rst
index 5aad4d1..cfe349f 100644
--- a/docs/classes.rst
+++ b/docs/classes.rst
@@ -177,9 +177,22 @@
std::string bark() const { return "woof!"; }
};
-To capture the hierarchical relationship in pybind11, we must assign a name to
-the ``Pet`` :class:`class_` instance and reference it when binding the ``Dog``
-class.
+There are two different ways of indicating a hierarchical relationship to
+pybind11: the first is by specifying the C++ base class explicitly during
+construction using the ``base`` attribute:
+
+.. code-block:: cpp
+
+ py::class_<Pet>(m, "Pet")
+ .def(py::init<const std::string &>())
+ .def_readwrite("name", &Pet::name);
+
+ py::class_<Dog>(m, "Dog", py::base<Pet>() /* <- specify C++ parent type */)
+ .def(py::init<const std::string &>())
+ .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:
.. code-block:: cpp
@@ -187,11 +200,12 @@
pet.def(py::init<const std::string &>())
.def_readwrite("name", &Pet::name);
- py::class_<Dog>(m, "Dog", pet /* <- specify parent */)
+ py::class_<Dog>(m, "Dog", pet /* <- specify Python parent type */)
.def(py::init<const std::string &>())
.def("bark", &Dog::bark);
-Instances then expose fields and methods of both types:
+Functionality-wise, both approaches are completely equivalent. Afterwards,
+instances will expose fields and methods of both types:
.. code-block:: python
@@ -242,14 +256,14 @@
| Methods defined here:
|
| __init__(...)
- | Signature : (Pet, str, int) -> None
+ | Signature : (Pet, str, int) -> NoneType
|
| set(...)
- | 1. Signature : (Pet, int) -> None
+ | 1. Signature : (Pet, int) -> NoneType
|
| Set the pet's age
|
- | 2. Signature : (Pet, str) -> None
+ | 2. Signature : (Pet, str) -> NoneType
|
| Set the pet's name
diff --git a/docs/cmake.rst b/docs/cmake.rst
index 50d50b5..6172859 100644
--- a/docs/cmake.rst
+++ b/docs/cmake.rst
@@ -30,10 +30,14 @@
# Try to autodetect Python (can be overridden manually if needed)
set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6 3.7)
if (NOT ${PYBIND11_PYTHON_VERSION} STREQUAL "")
- find_package(PythonLibs ${PYBIND11_PYTHON_VERSION} EXACT REQUIRED)
+ find_package(PythonLibs ${PYBIND11_PYTHON_VERSION} EXACT)
+ if (NOT PythonLibs_FOUND)
+ find_package(PythonLibs ${PYBIND11_PYTHON_VERSION} REQUIRED)
+ endif()
else()
find_package(PythonLibs REQUIRED)
endif()
+ find_package(PythonInterp ${PYTHONLIBS_VERSION_STRING} EXACT REQUIRED)
# Uncomment the following line if you will also require a matching Python interpreter
# find_package(PythonInterp ${PYTHONLIBS_VERSION_STRING} EXACT REQUIRED)
@@ -115,7 +119,7 @@
# Strip unnecessary sections of the binary on Linux/Mac OS
if(APPLE)
set_target_properties(example PROPERTIES MACOSX_RPATH ".")
- set_target_properties(example PROPERTIES LINK_FLAGS "-undefined dynamic_lookup -dead_strip")
+ set_target_properties(example PROPERTIES LINK_FLAGS "-undefined dynamic_lookup ")
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
add_custom_command(TARGET example POST_BUILD COMMAND strip -u -r ${PROJECT_BINARY_DIR}/example.so)
endif()
diff --git a/docs/reference.rst b/docs/reference.rst
index ab5c11b..4df4344 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -63,17 +63,19 @@
Return the ``PyObject *`` underlying a :class:`handle`.
-.. function:: void handle::inc_ref() const
+.. function:: const handle& handle::inc_ref() const
Manually increase the reference count of the Python object. Usually, it is
preferable to use the :class:`object` class which derives from
- :class:`handle` and calls this function automatically.
+ :class:`handle` and calls this function automatically. Returns a reference
+ to itself.
-.. function:: void handle::dec_ref() const
+.. function:: const handle& handle::dec_ref() const
Manually decrease the reference count of the Python object. Usually, it is
preferable to use the :class:`object` class which derives from
- :class:`handle` and calls this function automatically.
+ :class:`handle` and calls this function automatically. Returns a reference
+ to itself.
.. function:: void handle::ref_count() const
@@ -167,11 +169,11 @@
Move constructor; steals the object from ``other`` and preserves its
reference count.
-.. function:: PyObject* object::release()
+.. function:: handle object::release()
- Release ownership of underlying ``PyObject *``. Returns raw Python object
- pointer without decreasing its reference count and resets handle to
- ``nullptr``-valued pointer.
+ Resets the internal pointer to ``nullptr`` without without decreasing the
+ object's reference count. The function returns a raw handle to the original
+ Python object.
.. function:: object::~object()