Skip to content

Commit cffc586

Browse files
committed
Fix tests on 3.6 <= Python < 3.8
1 parent caa5382 commit cffc586

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

include/pybind11/cast.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,18 +1049,22 @@ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
10491049
if (index_check(src.ptr())) {
10501050
index = reinterpret_steal<object>(PyNumber_Index(src.ptr()));
10511051
if (!index) {
1052-
PyErr_Clear();
1053-
return false;
1052+
src_or_index = handle();
1053+
py_value = (py_type) -1;
1054+
}
1055+
else {
1056+
src_or_index = index;
10541057
}
1055-
src_or_index = index;
10561058
}
10571059
#endif
1058-
if (std::is_unsigned<py_type>::value) {
1059-
py_value = as_unsigned<py_type>(src_or_index.ptr());
1060-
} else { // signed integer:
1061-
py_value = sizeof(T) <= sizeof(long)
1062-
? (py_type) PyLong_AsLong(src_or_index.ptr())
1063-
: (py_type) PYBIND11_LONG_AS_LONGLONG(src_or_index.ptr());
1060+
if (src_or_index) {
1061+
if (std::is_unsigned<py_type>::value) {
1062+
py_value = as_unsigned<py_type>(src_or_index.ptr());
1063+
} else { // signed integer:
1064+
py_value = sizeof(T) <= sizeof(long)
1065+
? (py_type) PyLong_AsLong(src_or_index.ptr())
1066+
: (py_type) PYBIND11_LONG_AS_LONGLONG(src_or_index.ptr());
1067+
}
10641068
}
10651069
}
10661070

0 commit comments

Comments
 (0)