diff --git a/include/eigenpy/deprecation-policy.hpp b/include/eigenpy/deprecation-policy.hpp index c1635ea1..c69764b5 100644 --- a/include/eigenpy/deprecation-policy.hpp +++ b/include/eigenpy/deprecation-policy.hpp @@ -1,4 +1,5 @@ // +// Copyright (C) 2020 INRIA // Copyright (C) 2024 LAAS-CNRS, INRIA // #ifndef __eigenpy_deprecation_hpp__ @@ -23,11 +24,6 @@ constexpr PyObject *deprecationTypeToPyObj(DeprecationType dep) { } // namespace detail -constexpr char defaultDeprecationMessage[] = - "This function or attribute has been marked as deprecated, and will be " - "removed in the " - "future."; - /// @brief A Boost.Python call policy which triggers a Python warning on /// precall. template (this); @@ -53,10 +48,34 @@ struct deprecation_warning_policy : BasePolicy { return derived()->precall(args); } - private: + protected: const std::string m_what; }; +template +struct deprecated_function + : deprecation_warning_policy { + static constexpr char defaultMsg[] = + "This function has been marked as deprecated, and will be " + "removed in the future."; + + deprecated_function<>(const std::string &msg = defaultMsg) + : deprecation_warning_policy(msg) {} +}; + +template +struct deprecated_member + : deprecation_warning_policy { + static constexpr char defaultMsg[] = + "This attribute or method has been marked as deprecated, and will be " + "removed in the future."; + + deprecated_member(const std::string &msg = defaultMsg) + : deprecation_warning_policy(msg) {} +}; + } // namespace eigenpy #endif // ifndef __eigenpy_deprecation_hpp__ diff --git a/unittest/deprecation_policy.cpp b/unittest/deprecation_policy.cpp index d06d4954..c819f458 100644 --- a/unittest/deprecation_policy.cpp +++ b/unittest/deprecation_policy.cpp @@ -16,9 +16,18 @@ void some_future_deprecated_function() { << std::endl; } +class X { + public: + void deprecated_member_function() {} +}; + BOOST_PYTHON_MODULE(deprecation_policy) { bp::def("some_deprecated_function", some_deprecated_function, - eigenpy::deprecation_warning_policy()); + eigenpy::deprecated_function()); bp::def("some_future_deprecated_function", some_future_deprecated_function, - eigenpy::deprecation_warning_policy()); + eigenpy::deprecated_function()); + + bp::class_("X", bp::init<>(bp::args("self"))) + .def("deprecated_member_function", &X::deprecated_member_function, + eigenpy::deprecated_member<>()); } diff --git a/unittest/python/test_deprecation_policy.py b/unittest/python/test_deprecation_policy.py index b47550c7..46bc922c 100644 --- a/unittest/python/test_deprecation_policy.py +++ b/unittest/python/test_deprecation_policy.py @@ -1,4 +1,9 @@ -from deprecation_policy import some_deprecated_function, some_future_deprecated_function +from deprecation_policy import ( + X, + some_deprecated_function, + some_future_deprecated_function, +) some_deprecated_function() some_future_deprecated_function() +X().deprecated_member_function()