mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-06 05:39:53 +00:00
Raise codec errors when casting to std::string (#2903)
* Raise codec errors when casting to std::string Allow the codec's exception to be raised instead of RuntimeError when casting from py::str to std::string. PY2 allows ucs surrogates in UTF-8 conversion Signed-off-by: Shane Loretz <sloretz@openrobotics.org> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Attempt to fix py2 error * Revert all unicode literals * Fixed Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
This commit is contained in:
@@ -76,6 +76,9 @@ TEST_SUBMODULE(pytypes, m) {
|
||||
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_from_string_from_str", [](const py::str& obj) {
|
||||
return py::str(static_cast<std::string>(obj));
|
||||
});
|
||||
|
||||
m.def("str_format", []() {
|
||||
auto s1 = "{} + {} = {}"_s.format(1, 2, 3);
|
||||
|
||||
Reference in New Issue
Block a user