Drake
deprecation_pybind.h
Go to the documentation of this file.
1 #pragma once
2 
3 /// @file
4 /// Provides access to Python deprecation utilities from C++.
5 
6 #include "pybind11/pybind11.h"
7 
9 
10 namespace drake {
11 namespace pydrake {
12 
13 /// Deprecates an attribute `name` of a class `cls`.
14 /// This *only* works with class attributes (unbound members or methods) as it
15 /// is implemented with a Python property descriptor.
16 inline void DeprecateAttribute(
17  py::object cls, py::str name, py::str message) {
18  py::object deprecated =
19  py::module::import("pydrake.util.deprecation").attr("deprecated");
20  py::object original = cls.attr(name);
21  cls.attr(name) = deprecated(message)(original);
22 }
23 
24 /// Raises a deprecation warning.
25 ///
26 /// @note If you are deprecating a class's member or method, please use
27 /// `DeprecateAttribute` so that the warning is issued immediately when
28 /// accessed, not only when it is called.
29 inline void WarnDeprecated(py::str message) {
30  py::object warn_deprecated =
31  py::module::import("pydrake.util.deprecation").attr("_warn_deprecated");
32  warn_deprecated(message);
33 }
34 
35 } // namespace pydrake
36 } // namespace drake
void DeprecateAttribute(py::object cls, py::str name, py::str message)
Deprecates an attribute name of a class cls.
Definition: deprecation_pybind.h:16
Definition: bullet_model.cc:22
void WarnDeprecated(py::str message)
Raises a deprecation warning.
Definition: deprecation_pybind.h:29
std::string name
Definition: geometry_base_test.cc:343