@@ -733,7 +733,9 @@ class generic_iterator : public Policy {
733733 generic_iterator () = default ;
734734 generic_iterator (handle seq, ssize_t index) : Policy (seq, index) { }
735735
736+ // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
736737 reference operator *() const { return Policy::dereference (); }
738+ // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
737739 reference operator [](difference_type n) const { return *(*this + n); }
738740 pointer operator ->() const { return **this ; }
739741
@@ -773,11 +775,12 @@ class sequence_fast_readonly {
773775protected:
774776 using iterator_category = std::random_access_iterator_tag;
775777 using value_type = handle;
776- using reference = const handle;
778+ using reference = const handle; // PR #3263
777779 using pointer = arrow_proxy<const handle>;
778780
779781 sequence_fast_readonly (handle obj, ssize_t n) : ptr(PySequence_Fast_ITEMS(obj.ptr()) + n) { }
780782
783+ // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
781784 reference dereference () const { return *ptr; }
782785 void increment () { ++ptr; }
783786 void decrement () { --ptr; }
@@ -816,12 +819,13 @@ class dict_readonly {
816819protected:
817820 using iterator_category = std::forward_iterator_tag;
818821 using value_type = std::pair<handle, handle>;
819- using reference = const value_type;
822+ using reference = const value_type; // PR #3263
820823 using pointer = arrow_proxy<const value_type>;
821824
822825 dict_readonly () = default ;
823826 dict_readonly (handle obj, ssize_t pos) : obj(obj), pos(pos) { increment (); }
824827
828+ // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
825829 reference dereference () const { return {key, value}; }
826830 void increment () {
827831 if (PyDict_Next (obj.ptr (), &pos, &key, &value) == 0 ) {
@@ -966,7 +970,7 @@ class iterator : public object {
966970 using iterator_category = std::input_iterator_tag;
967971 using difference_type = ssize_t ;
968972 using value_type = handle;
969- using reference = const handle;
973+ using reference = const handle; // PR #3263
970974 using pointer = const handle *;
971975
972976 PYBIND11_OBJECT_DEFAULT (iterator, object, PyIter_Check)
@@ -982,6 +986,7 @@ class iterator : public object {
982986 return rv;
983987 }
984988
989+ // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
985990 reference operator *() const {
986991 if (m_ptr && !value.ptr ()) {
987992 auto & self = const_cast <iterator &>(*this );
@@ -1414,14 +1419,19 @@ class capsule : public object {
14141419 T* get_pointer () const {
14151420 auto name = this ->name ();
14161421 T *result = static_cast <T *>(PyCapsule_GetPointer (m_ptr, name));
1417- if (!result) pybind11_fail (" Unable to extract capsule contents!" );
1422+ if (!result) {
1423+ PyErr_Clear ();
1424+ pybind11_fail (" Unable to extract capsule contents!" );
1425+ }
14181426 return result;
14191427 }
14201428
14211429 // / Replaces a capsule's pointer *without* calling the destructor on the existing one.
14221430 void set_pointer (const void *value) {
1423- if (PyCapsule_SetPointer (m_ptr, const_cast <void *>(value)) != 0 )
1431+ if (PyCapsule_SetPointer (m_ptr, const_cast <void *>(value)) != 0 ) {
1432+ PyErr_Clear ();
14241433 pybind11_fail (" Could not set capsule pointer" );
1434+ }
14251435 }
14261436
14271437 const char *name () const { return PyCapsule_GetName (m_ptr); }
0 commit comments