Similar to Python `warnings.warn()`
| 58 | |
| 59 | // Similar to Python `warnings.warn()` |
| 60 | inline void |
| 61 | warn(const char *message, handle category = PyExc_RuntimeWarning, int stack_level = 2) { |
| 62 | if (!detail::PyWarning_Check(category.ptr())) { |
| 63 | pybind11_fail( |
| 64 | "pybind11::warnings::warn(): cannot raise warning, category must be a subclass of " |
| 65 | "PyExc_Warning!"); |
| 66 | } |
| 67 | |
| 68 | if (PyErr_WarnEx(category.ptr(), message, stack_level) == -1) { |
| 69 | throw error_already_set(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | PYBIND11_NAMESPACE_END(warnings) |
| 74 |