Update docs

This commit is contained in:
jiwaszki 2024-10-01 00:30:52 +02:00
parent 2fbd013434
commit 706ece4ba5

View File

@ -331,17 +331,17 @@ an invalid state.
Handling warnings from the Python C API Handling warnings from the Python C API
===================================== =====================================
Where possible, use :ref:`pybind11 warnings <warnings>` instead of calling Wrappers for handling Python warnings are implemented in ``pybind11/warnings.h``,
the Python C API directly. The motivation is similar to previously mentioned errors. which must be ``#include``ed explicitly (in other words, it is not transitively
All warnings categories are required to be a subclass of ``PyExc_Warning`` from Python C API. included with ``pybind11/pybind11.h``).
Warnings can be raised with ``warn`` function: Warnings can be raised with the ``warn`` function:
.. code-block:: cpp .. code-block:: cpp
py::warnings::warn("This is warning!", PyExc_Warning); py::warnings::warn("This is warning!", PyExc_Warning);
// When calling `stack_level` can be specified as well. // Optionally, `stack_level` can be specified.
py::warnings::warn("Another one!", PyExc_DeprecationWarning, 3); py::warnings::warn("Another one!", PyExc_DeprecationWarning, 3);
New warning types can be registered on the module level with ``new_warning_type``: New warning types can be registered on the module level with ``new_warning_type``:
@ -350,8 +350,6 @@ New warning types can be registered on the module level with ``new_warning_type`
py::warnings::new_warning_type(m, "CustomWarning", PyExc_RuntimeWarning); py::warnings::new_warning_type(m, "CustomWarning", PyExc_RuntimeWarning);
.. versionadded:: 2.14
Chaining exceptions ('raise from') Chaining exceptions ('raise from')
================================== ==================================