-
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
feat: add py::set_error()
, use in updated py::exception<>
documentation
#4772
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Copy clang 17 compatibility fixes from PR pybind#4762 to a separate PR. * Add gcc:13 C++20 * Add silkeh/clang:16-bullseye C++20
updates: - [github.com/psf/black: 23.3.0 → 23.7.0](psf/black@23.3.0...23.7.0) - [github.com/astral-sh/ruff-pre-commit: v0.0.276 → v0.0.281](astral-sh/ruff-pre-commit@v0.0.276...v0.0.281) - [github.com/asottile/blacken-docs: 1.14.0 → 1.15.0](adamchainz/blacken-docs@1.14.0...1.15.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…tuptools (pybind#4774) * docs: Remove upper bound on pybind11 in example pyproject.toml for setuptools * Update docs/compiling.rst --------- Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
* Provide better type hints for a variety of generic types * Makes better documentation * tuple, dict, list, set, function * Move to py::typing * style: pre-commit fixes * Update copyright line with correct year and actual author. The author information was copy-pasted from the git log output. --------- Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…common.h). Overload `py::set_error(py::handle, py::handle)`. Change back to `static py::handle exc = ... .release();` Deprecate `py::exception<>::operator()`
rwgk
changed the title
WIP: static py::exception
Add Aug 4, 2023
py::set_error()
, use in updated py::exception<>
documentation
For ICC only, falling back to the recommended `py::set_error()` to keep the testing simple. It is troublesome to add `--diag-disable=10441` specifically for test_exceptions.cpp, even that is non-ideal because it covers the entire file, not just the one line we need it for, and the value of exercising the trivial deprecated `operator()` on this one extra platform is practically zero.
…reated as errors, but falling back to using `py::set_error()` to not have to deal with that distraction.
@albanD Could you please review and let me know any suggestions? |
albanD
approved these changes
Aug 6, 2023
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.
The new documentation and code looks good to me. It does make the doc surprisingly simpler to have set_error().
The rest of the update in the code looks good to me as well!
henryiii
approved these changes
Aug 7, 2023
Skylion007
approved these changes
Aug 7, 2023
Thanks for the reviews! |
henryiii
changed the title
Add
feat: add Nov 15, 2023
py::set_error()
, use in updated py::exception<>
documentationpy::set_error()
, use in updated py::exception<>
documentation
This was referenced Mar 28, 2024
8 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Related discussions:
This PR is much simpler than it might appear at first sight.
It adds two very simple
py::set_error()
functions in include/pybind11/pytypes.hSprawling but trivial changes: use the new functions everywhere to replace
PyErr_SetString()
andPyErr_SetObject()
calls.Update the
py::exception<>
documentation to not suggest code that may result in undefined behavior: thestatic py::exception<>
destructor may run after the Python interpreter is finalized already.Deprecate
py::exception<>::operator()
. It is evidently more likely to cause confusion (see Fix lifetime of JITException binding pytorch/pytorch#106401) than being helpful. Directing users to usepy::set_error()
universally is much simpler, there is nothing special to learn or remember.Suggested changelog entry: