Skip to content

Commit 16f199f

Browse files
Change base parameter type in register_exception and exception constructor from PyObject* to handle (#2467)
* Change base parameter type in register_exception and excepion constructor from PyObject* to handle * Fix compilation error passing `handle` to `PyObject*`
1 parent e7bafc8 commit 16f199f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

docs/advanced/exceptions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module and automatically converts any encountered exceptions of type ``CppExp``
8080
into Python exceptions of type ``PyExp``.
8181

8282
It is possible to specify base class for the exception using the third
83-
parameter, a pointer to `PyObject`:
83+
parameter, a `handle`:
8484

8585
.. code-block:: cpp
8686

include/pybind11/pybind11.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,10 +1868,10 @@ template <typename type>
18681868
class exception : public object {
18691869
public:
18701870
exception() = default;
1871-
exception(handle scope, const char *name, PyObject *base = PyExc_Exception) {
1871+
exception(handle scope, const char *name, handle base = PyExc_Exception) {
18721872
std::string full_name = scope.attr("__name__").cast<std::string>() +
18731873
std::string(".") + name;
1874-
m_ptr = PyErr_NewException(const_cast<char *>(full_name.c_str()), base, NULL);
1874+
m_ptr = PyErr_NewException(const_cast<char *>(full_name.c_str()), base.ptr(), NULL);
18751875
if (hasattr(scope, name))
18761876
pybind11_fail("Error during initialization: multiple incompatible "
18771877
"definitions with name \"" + std::string(name) + "\"");
@@ -1901,7 +1901,7 @@ PYBIND11_NAMESPACE_END(detail)
19011901
template <typename CppException>
19021902
exception<CppException> &register_exception(handle scope,
19031903
const char *name,
1904-
PyObject *base = PyExc_Exception) {
1904+
handle base = PyExc_Exception) {
19051905
auto &ex = detail::get_exception_object<CppException>();
19061906
if (!ex) ex = exception<CppException>(scope, name, base);
19071907

0 commit comments

Comments
 (0)