@@ -70,7 +70,6 @@ class object_api : public pyobject_tag {
70
70
bool is_none () const { return derived ().ptr () == Py_None; }
71
71
PYBIND11_DEPRECATED (" Instead of obj.str(), use py::str(obj)" )
72
72
pybind11::str str () const ;
73
- pybind11::str repr () const ;
74
73
75
74
int ref_count () const { return static_cast <int >(Py_REFCNT (derived ().ptr ())); }
76
75
handle get_type () const ;
@@ -833,6 +832,17 @@ inline size_t len(handle h) {
833
832
return (size_t ) result;
834
833
}
835
834
835
+ inline str repr (handle h) {
836
+ PyObject *str_value = PyObject_Repr (h.ptr ());
837
+ if (!str_value) throw error_already_set ();
838
+ #if PY_MAJOR_VERSION < 3
839
+ PyObject *unicode = PyUnicode_FromEncodedObject (str_value, " utf-8" , nullptr );
840
+ Py_XDECREF (str_value); str_value = unicode;
841
+ if (!str_value) throw error_already_set ();
842
+ #endif
843
+ return {str_value, false };
844
+ }
845
+
836
846
NAMESPACE_BEGIN (detail)
837
847
template <typename D> iterator object_api<D>::begin() const { return {PyObject_GetIter (derived ().ptr ()), false }; }
838
848
template <typename D> iterator object_api<D>::end() const { return {nullptr , false }; }
@@ -848,16 +858,6 @@ template <typename D> template <typename T> bool object_api<D>::contains(T &&key
848
858
template <typename D>
849
859
pybind11::str object_api<D>::str() const { return pybind11::str (derived ()); }
850
860
851
- template <typename D>
852
- pybind11::str object_api<D>::repr() const {
853
- PyObject *str_value = PyObject_Repr (derived ().ptr ());
854
- #if PY_MAJOR_VERSION < 3
855
- PyObject *unicode = PyUnicode_FromEncodedObject (str_value, " utf-8" , nullptr );
856
- Py_XDECREF (str_value); str_value = unicode;
857
- #endif
858
- return {str_value, false };
859
- }
860
-
861
861
template <typename D>
862
862
handle object_api<D>::get_type() const { return (PyObject *) Py_TYPE (derived ().ptr ()); }
863
863
0 commit comments