File tree 1 file changed +9
-1
lines changed 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -1020,14 +1020,22 @@ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
1020
1020
if (!src)
1021
1021
return false ;
1022
1022
1023
+ #if !defined(PYPY_VERSION)
1024
+ auto index_check = [](PyObject *o) { return PyIndex_Check (o); };
1025
+ #else
1026
+ // In PyPy 7.3.3, `PyIndex_Check` is implemented by calling `__index__`,
1027
+ // while CPython only considers the existence of `nb_index`/`__index__`.
1028
+ auto index_check = [](PyObject *o) { return hasattr (o, " __index__" ); };
1029
+ #endif
1030
+
1023
1031
if (std::is_floating_point<T>::value) {
1024
1032
if (convert || PyFloat_Check (src.ptr ()))
1025
1033
py_value = (py_type) PyFloat_AsDouble (src.ptr ());
1026
1034
else
1027
1035
return false ;
1028
1036
} else if (PyFloat_Check (src.ptr ())) {
1029
1037
return false ;
1030
- } else if (!convert && !PyIndex_Check (src.ptr ()) && !PYBIND11_LONG_CHECK (src.ptr ())) {
1038
+ } else if (!convert && !index_check (src.ptr ()) && !PYBIND11_LONG_CHECK (src.ptr ())) {
1031
1039
return false ;
1032
1040
} else if (std::is_unsigned<py_type>::value) {
1033
1041
py_value = as_unsigned<py_type>(src.ptr ());
You can’t perform that action at this time.
0 commit comments