-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation entry for warnings #5356
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
an invalid state. | ||
|
||
Handling warnings from the Python C API | ||
===================================== | ||
|
||
Where possible, use :ref:`pybind11 warnings <warnings>` instead of calling | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This I don't know if you want to go in fixing the existing problem, up to you. Here I'd simply write (i.e. replace this entire paragraph, lines 334-336, with):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have copied your text over (with small change to fit docs requirements, "I don't know if you want to go in fixing the existing problem" -- I would not get into it right now...:)). |
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it! It's way simpler... 😄 |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rwgk I cannot predict roadmap for versioning... is 2.14 okay? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, I'm switching employers (last day today, first day Monday). I'll try to get back here asap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rwgk Congrats and my best wishes for your next chapter! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks!
We only keep track of this in the Changelog. Please omit here. |
||
|
||
Chaining exceptions ('raise from') | ||
================================== | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a couple more
=
, to line up with the text above?(I overlooked this before.)