Skip to content

Commit 6f270a3

Browse files
committed
Backing out changes originating from #2392.
1 parent c7ba900 commit 6f270a3

File tree

3 files changed

+2
-20
lines changed

3 files changed

+2
-20
lines changed

include/pybind11/pytypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ class str : public object {
925925
Return a string representation of the object. This is analogous to
926926
the ``str()`` function in Python.
927927
\endrst */
928-
explicit str(handle h) : object(raw_str(h.ptr()), stolen_t{}) { if (!m_ptr) throw error_already_set(); }
928+
explicit str(handle h) : object(raw_str(h.ptr()), stolen_t{}) { }
929929

930930
operator std::string() const {
931931
object temp = *this;
@@ -950,8 +950,8 @@ class str : public object {
950950
/// Return string representation -- always returns a new reference, even if already a str
951951
static PyObject *raw_str(PyObject *op) {
952952
PyObject *str_value = PyObject_Str(op);
953-
#if PY_MAJOR_VERSION < 3
954953
if (!str_value) throw error_already_set();
954+
#if PY_MAJOR_VERSION < 3
955955
PyObject *unicode = PyUnicode_FromEncodedObject(str_value, "utf-8", nullptr);
956956
Py_XDECREF(str_value); str_value = unicode;
957957
#endif

tests/test_pytypes.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ TEST_SUBMODULE(pytypes, m) {
8080
m.def("str_from_bytes", []() { return py::str(py::bytes("boo", 3)); });
8181
m.def("str_from_object", [](const py::object& obj) { return py::str(obj); });
8282
m.def("repr_from_object", [](const py::object& obj) { return py::repr(obj); });
83-
m.def("str_from_handle", [](py::handle h) { return py::str(h); });
8483

8584
m.def("str_format", []() {
8685
auto s1 = "{} + {} = {}"_s.format(1, 2, 3);

tests/test_pytypes.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,11 @@ def __repr__(self):
104104

105105
assert m.str_from_object(A()) == "this is a str"
106106
assert m.repr_from_object(A()) == "this is a repr"
107-
assert m.str_from_handle(A()) == "this is a str"
108107

109108
s1, s2 = m.str_format()
110109
assert s1 == "1 + 2 = 3"
111110
assert s1 == s2
112111

113-
malformed_utf8 = b"\x80"
114-
if env.PY2:
115-
if hasattr(m, "has_str_non_permissive"):
116-
with pytest.raises(UnicodeDecodeError):
117-
m.str_from_object(malformed_utf8)
118-
else:
119-
m.str_from_object(malformed_utf8) is malformed_utf8
120-
with pytest.raises(UnicodeDecodeError):
121-
m.str_from_handle(malformed_utf8)
122-
else:
123-
if hasattr(m, "has_str_non_permissive"):
124-
assert m.str_from_object(malformed_utf8) == "b'\\x80'"
125-
else:
126-
assert m.str_from_object(malformed_utf8) is malformed_utf8
127-
assert m.str_from_handle(malformed_utf8) == "b'\\x80'"
128-
129112

130113
def test_bytes(doc):
131114
assert m.bytes_from_string().decode() == "foo"

0 commit comments

Comments
 (0)