diff --git a/docs/classes.rst b/docs/classes.rst index 80f378f68..4270b8d6d 100644 --- a/docs/classes.rst +++ b/docs/classes.rst @@ -185,10 +185,9 @@ inheritance relationship: std::string bark() const { return "woof!"; } }; -There are three different ways of indicating a hierarchical relationship to +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_`; the second uses a special ``base`` attribute -passed into the constructor: +parameter of the :class:`class_`: .. code-block:: cpp @@ -201,11 +200,6 @@ passed into the constructor: .def(py::init()) .def("bark", &Dog::bark); - // Method 2: py::base attribute: - py::class_(m, "Dog", py::base() /* <- specify C++ parent type */) - .def(py::init()) - .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: @@ -215,13 +209,13 @@ Alternatively, we can also assign a name to the previously bound ``Pet`` pet.def(py::init()) .def_readwrite("name", &Pet::name); - // Method 3: pass parent class_ object: + // Method 2: pass parent class_ object: py::class_(m, "Dog", pet /* <- specify Python parent type */) .def(py::init()) .def("bark", &Dog::bark); -Functionality-wise, all three approaches are completely equivalent. Afterwards, -instances will expose fields and methods of both types: +Functionality-wise, both approaches are equivalent. Afterwards, instances will +expose fields and methods of both types: .. code-block:: pycon diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index e3434b145..070d9d9d8 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -33,7 +33,10 @@ struct name { const char *value; name(const char *value) : value(value) { } }; struct sibling { handle value; sibling(const handle &value) : value(value.ptr()) { } }; /// Annotation indicating that a class derives from another given type -template struct base { }; +template struct base { + PYBIND11_DEPRECATED("base() was deprecated in favor of specifying 'T' as a template argument to class_") + base() { } +}; /// Keep patient alive while nurse lives template struct keep_alive { }; diff --git a/include/pybind11/common.h b/include/pybind11/common.h index fd65fe762..164e381b8 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -30,6 +30,16 @@ # define PYBIND11_NOINLINE __attribute__ ((noinline)) #endif +#if __cplusplus > 201103L +# define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]] +#elif defined(__clang__) +# define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason))) +#elif defined(__GNUG__) +# define PYBIND11_DEPRECATED(reason) __attribute__((deprecated)) +#elif defined(_MSC_VER) +# define PYBIND11_DEPRECATED(reason) __declspec(deprecated) +#endif + #define PYBIND11_VERSION_MAJOR 1 #define PYBIND11_VERSION_MINOR 9 #define PYBIND11_VERSION_PATCH dev0 diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index ba5d2c4c6..56ebb7f31 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -43,10 +43,8 @@ public: bool is_none() const { return m_ptr == Py_None; } template T cast() const; template - #if __cplusplus > 201103L - [[deprecated("call(...) was deprecated in favor of operator()(...)")]] - #endif - object call(Args&&... args) const; + PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)") + object call(Args&&... args) const; template object operator()(Args&&... args) const; operator bool() const { return m_ptr != nullptr; }