File tree 3 files changed +2
-20
lines changed 3 files changed +2
-20
lines changed Original file line number Diff line number Diff line change @@ -925,7 +925,7 @@ class str : public object {
925
925
Return a string representation of the object. This is analogous to
926
926
the ``str()`` function in Python.
927
927
\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{}) { }
929
929
930
930
operator std::string () const {
931
931
object temp = *this ;
@@ -950,8 +950,8 @@ class str : public object {
950
950
// / Return string representation -- always returns a new reference, even if already a str
951
951
static PyObject *raw_str (PyObject *op) {
952
952
PyObject *str_value = PyObject_Str (op);
953
- #if PY_MAJOR_VERSION < 3
954
953
if (!str_value) throw error_already_set ();
954
+ #if PY_MAJOR_VERSION < 3
955
955
PyObject *unicode = PyUnicode_FromEncodedObject (str_value, " utf-8" , nullptr );
956
956
Py_XDECREF (str_value); str_value = unicode;
957
957
#endif
Original file line number Diff line number Diff line change @@ -80,7 +80,6 @@ TEST_SUBMODULE(pytypes, m) {
80
80
m.def (" str_from_bytes" , []() { return py::str (py::bytes (" boo" , 3 )); });
81
81
m.def (" str_from_object" , [](const py::object& obj) { return py::str (obj); });
82
82
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); });
84
83
85
84
m.def (" str_format" , []() {
86
85
auto s1 = " {} + {} = {}" _s.format (1 , 2 , 3 );
Original file line number Diff line number Diff line change @@ -104,28 +104,11 @@ def __repr__(self):
104
104
105
105
assert m .str_from_object (A ()) == "this is a str"
106
106
assert m .repr_from_object (A ()) == "this is a repr"
107
- assert m .str_from_handle (A ()) == "this is a str"
108
107
109
108
s1 , s2 = m .str_format ()
110
109
assert s1 == "1 + 2 = 3"
111
110
assert s1 == s2
112
111
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
-
129
112
130
113
def test_bytes (doc ):
131
114
assert m .bytes_from_string ().decode () == "foo"
You can’t perform that action at this time.
0 commit comments