Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jiwaszki
Copy link
Contributor

@jiwaszki jiwaszki commented Sep 5, 2024

Description

Documentation entry for #5291 - short explanation of new py::warnings namespace.


py::warnings::new_warning_type(m, "CustomWarning", PyExc_RuntimeWarning);

.. versionadded:: 2.14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwgk I cannot predict roadmap for versioning... is 2.14 okay?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwgk Congrats and my best wishes for your next chapter!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats and my best wishes for your next chapter!

Thanks!

.. versionadded:: 2.14

We only keep track of this in the Changelog. Please omit here.

Handling warnings from the Python C API
=====================================

Where possible, use :ref:`pybind11 warnings <warnings>` instead of calling
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This :ref: does not work, just like the existing one above (line 307 here).

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):

Wrappers for handling Python warnings are implemented in ``pybind11/warnings.h``, which must be ``#include``ed explicitly (in other words, it is not transitively included with ``pybind11/pybind11.h``).

Copy link
Contributor Author

@jiwaszki jiwaszki Sep 30, 2024

Choose a reason for hiding this comment

The 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...:)).


py::warnings::warn("This is warning!", PyExc_Warning);

// When calling `stack_level` can be specified as well.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

   // Optionally, `stack_level` can be specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! It's way simpler... 😄


py::warnings::new_warning_type(m, "CustomWarning", PyExc_RuntimeWarning);

.. versionadded:: 2.14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats and my best wishes for your next chapter!

Thanks!

.. versionadded:: 2.14

We only keep track of this in the Changelog. Please omit here.

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd give it an extra "the":

Warnings can be raised with the ``warn`` function:

@jiwaszki jiwaszki requested a review from rwgk October 3, 2024 00:42
=====================================

Wrappers for handling Python warnings are implemented in ``pybind11/warnings.h``,
which means that ``#include`` must be added explicitly (in other words, it is not
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which means is not correct here. It was a choice to not include warnings.h in pybind11.h. We just want to state that here, to be helpful.

Could you please change this to

which must be included explicitly?

@@ -328,6 +328,28 @@ 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
=====================================
Copy link
Collaborator

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants