Uh oh!
There was an error while loading. Please reload this page.
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.
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.hand 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()`` wrappertemplate <typename F> voidignoreOldStyleInitWarnings(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()); }
henryiii
left a comment
There was a problem hiding this comment.
All test changes to avoid warnings because we are intentionally checking things that warn, looks good to me.
bstaletic
left a comment
There was a problem hiding this comment.
Since I helped with the PR, am I allowed to approve?
YannickJadoul
commented
Jan 1, 2021
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 placementnews) 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: