-
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
Ignore deprecation warnings about old-style __init__/__setstate__ constructors in the tests (originally done in #2746) #2759
Ignore deprecation warnings about old-style __init__/__setstate__ constructors in the tests (originally done in #2746) #2759
Conversation
|
||
template <typename F> | ||
void ignoreOldStyleInitWarnings(F &&body) { | ||
py::exec(R"( |
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.
Comment from #2746:
-
@YannickJadoul: For reference, this was the old code, without
py::exec
(and thus without requiring<pybind11/eval.h>
to be included inpybind11_tests.h
and thus in all tests).@bstaletic slightly prefers this [new version], and I think I do to. However, curious to learn what other reviewers think.
/// Simplified ``with warnigns.catch_warnings()`` wrapper template <typename F> void ignoreOldStyleInitWarnings(F &&body) { auto message = "pybind11-bound class '.+' is using an old-style placement-new '(?:__init__|__setstate__)' which has been deprecated"; auto category = py::reinterpret_borrow<py::object>(PyExc_FutureWarning); auto warnings = py::module_::import("warnings"); auto context_mgr = warnings.attr("catch_warnings")(); context_mgr.attr("__enter__")(); warnings.attr("filterwarnings")("ignore", py::arg("message")=message, py::arg("category")=category); body(); // Exceptions in `body` not handled; see PEP 343 when these would need to be added context_mgr.attr("__exit__")(py::none(), py::none(), py::none()); }
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.
All test changes to avoid warnings because we are intentionally checking things that warn, looks good to me.
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.
Since I helped with the PR, am I allowed to approve?
Let's merge this, then? If anyone objects against |
Description
As the title says. The test suite contains a few tests to make sure the old-style
__init__
(with placementnew
s) still works and interacts correctly with the new, non-deprecated way of doing things. Using a debug build of Python (in #2746), pybind11 shows these deprecation warnings, so let's filter these out to remove some output clutter and make sure we have a higher chance of catching useful warnings.Suggested changelog entry: