Add check if str(handle) correctly converted the object, and throw py::error_already_set if not (bis) (#2477)

* Add check if `str(handle)` correctly converted the object, and throw py::error_already_set if not

* Fix tests on Python 3

* Apply @rwgk's fixes to cherry-picked commits from #2392
This commit is contained in:
Yannick Jadoul
2020-09-11 19:53:04 +02:00
committed by GitHub
parent b47efd35fb
commit fe9ee86ba8
3 changed files with 15 additions and 2 deletions

View File

@@ -80,6 +80,7 @@ TEST_SUBMODULE(pytypes, m) {
m.def("str_from_bytes", []() { return py::str(py::bytes("boo", 3)); });
m.def("str_from_object", [](const py::object& obj) { return py::str(obj); });
m.def("repr_from_object", [](const py::object& obj) { return py::repr(obj); });
m.def("str_from_handle", [](py::handle h) { return py::str(h); });
m.def("str_format", []() {
auto s1 = "{} + {} = {}"_s.format(1, 2, 3);