MCPcopy Create free account
hub / github.com/pybind/pybind11 / warn

Function warn

include/pybind11/warnings.h:60–71  ·  view source on GitHub ↗

Similar to Python `warnings.warn()`

Source from the content-addressed store, hash-verified

58
59// Similar to Python `warnings.warn()`
60inline void
61warn(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
73PYBIND11_NAMESPACE_END(warnings)
74

Callers 1

TEST_SUBMODULEFunction · 0.85

Calls 2

PyWarning_CheckFunction · 0.85
ptrMethod · 0.80

Tested by 1

TEST_SUBMODULEFunction · 0.68