@@ -149,39 +149,39 @@ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
149149 }
150150 } else {
151151#if !defined(PYPY_VERSION)
152- auto index_check = [](PyObject *o) { return PyIndex_Check (o); };
152+ auto index_check = [](PyObject *o) { return PyIndex_Check (o); };
153153#else
154- // In PyPy 7.3.3, `PyIndex_Check` is implemented by calling `__index__`,
155- // while CPython only considers the existence of `nb_index`/`__index__`.
156- auto index_check = [](PyObject *o) { return hasattr (o, " __index__" ); };
154+ // In PyPy 7.3.3, `PyIndex_Check` is implemented by calling `__index__`,
155+ // while CPython only considers the existence of `nb_index`/`__index__`.
156+ auto index_check = [](PyObject *o) { return hasattr (o, " __index__" ); };
157157#endif
158- if (PyFloat_Check (src.ptr ())
159- || (!convert && !PYBIND11_LONG_CHECK (src.ptr ()) && !index_check (src.ptr ()))) {
160- return false ;
161- }
158+ if (PyFloat_Check (src.ptr ())
159+ || (!convert && !PYBIND11_LONG_CHECK (src.ptr ()) && !index_check (src.ptr ()))) {
160+ return false ;
161+ }
162162
163- handle src_or_index = src;
164- // PyPy: 7.3.7's 3.8 does not implement PyLong_*'s __index__ calls.
163+ handle src_or_index = src;
164+ // PyPy: 7.3.7's 3.8 does not implement PyLong_*'s __index__ calls.
165165#if defined(PYPY_VERSION)
166- object index;
167- if (!PYBIND11_LONG_CHECK (src.ptr ())) { // So: index_check(src.ptr())
168- index = reinterpret_steal<object>(PyNumber_Index (src.ptr ()));
169- if (!index) {
170- PyErr_Clear ();
171- if (!convert)
172- return false ;
173- } else {
174- src_or_index = index;
166+ object index;
167+ if (!PYBIND11_LONG_CHECK (src.ptr ())) { // So: index_check(src.ptr())
168+ index = reinterpret_steal<object>(PyNumber_Index (src.ptr ()));
169+ if (!index) {
170+ PyErr_Clear ();
171+ if (!convert)
172+ return false ;
173+ } else {
174+ src_or_index = index;
175+ }
175176 }
176- }
177177#endif
178- if PYBIND11_IF_CONSTEXPR (std::is_unsigned<py_type>::value) {
179- py_value = as_unsigned<py_type>(src_or_index.ptr ());
180- } else { // signed integer:
181- py_value = sizeof (T) <= sizeof (long )
182- ? (py_type) PyLong_AsLong (src_or_index.ptr ())
183- : (py_type) PYBIND11_LONG_AS_LONGLONG (src_or_index.ptr ());
184- }
178+ if PYBIND11_IF_CONSTEXPR (std::is_unsigned<py_type>::value) {
179+ py_value = as_unsigned<py_type>(src_or_index.ptr ());
180+ } else { // signed integer:
181+ py_value = sizeof (T) <= sizeof (long )
182+ ? (py_type) PyLong_AsLong (src_or_index.ptr ())
183+ : (py_type) PYBIND11_LONG_AS_LONGLONG (src_or_index.ptr ());
184+ }
185185 }
186186
187187 // Python API reported an error
0 commit comments