Compare commits

...

4 Commits

Author SHA1 Message Date
Jan Iwaszkiewicz 184db0d33b
Merge 2fbd013434 into 1f8b4a7f1a 2024-09-20 23:40:37 -07:00
Hintay 1f8b4a7f1a
fix(cmake): `NO_EXTRAS` in `pybind11_add_module` function partially working (#5378) 2024-09-19 11:24:35 -04:00
jiwaszki 2fbd013434 Fix code formatting 2024-09-05 23:59:11 +02:00
jiwaszki 7266988540 [docs] Add entry for warnings 2024-09-05 23:28:53 +02:00
2 changed files with 24 additions and 4 deletions

View File

@ -328,6 +328,30 @@ Alternately, to ignore the error, call `PyErr_Clear
Any Python error must be thrown or cleared, or Python/pybind11 will be left in Any Python error must be thrown or cleared, or Python/pybind11 will be left in
an invalid state. an invalid state.
Handling warnings from the Python C API
=====================================
Where possible, use :ref:`pybind11 warnings <warnings>` instead of calling
the Python C API directly. The motivation is similar to previously mentioned errors.
All warnings categories are required to be a subclass of ``PyExc_Warning`` from Python C API.
Warnings can be raised with ``warn`` function:
.. code-block:: cpp
py::warnings::warn("This is warning!", PyExc_Warning);
// When calling `stack_level` can be specified as well.
py::warnings::warn("Another one!", PyExc_DeprecationWarning, 3);
New warning types can be registered on the module level with ``new_warning_type``:
.. code-block:: cpp
py::warnings::new_warning_type(m, "CustomWarning", PyExc_RuntimeWarning);
.. versionadded:: 2.14
Chaining exceptions ('raise from') Chaining exceptions ('raise from')
================================== ==================================

View File

@ -274,10 +274,6 @@ function(pybind11_add_module target_name)
target_link_libraries(${target_name} PRIVATE pybind11::embed) target_link_libraries(${target_name} PRIVATE pybind11::embed)
endif() endif()
if(MSVC)
target_link_libraries(${target_name} PRIVATE pybind11::windows_extras)
endif()
# -fvisibility=hidden is required to allow multiple modules compiled against # -fvisibility=hidden is required to allow multiple modules compiled against
# different pybind versions to work properly, and for some features (e.g. # different pybind versions to work properly, and for some features (e.g.
# py::module_local). We force it on everything inside the `pybind11` # py::module_local). We force it on everything inside the `pybind11`