@@ -737,12 +737,12 @@ template <typename T1, typename T2> class type_caster<std::pair<T1, T2>> {
737
737
typedef std::pair<T1, T2> type;
738
738
public:
739
739
bool load (handle src, bool convert) {
740
- if (!src)
740
+ if (!isinstance<sequence>( src) )
741
741
return false ;
742
- else if (!PyTuple_Check (src.ptr ()) || PyTuple_Size (src.ptr ()) != 2 )
742
+ const auto seq = reinterpret_borrow<sequence>(src);
743
+ if (seq.size () != 2 )
743
744
return false ;
744
- return first.load (PyTuple_GET_ITEM (src.ptr (), 0 ), convert) &&
745
- second.load (PyTuple_GET_ITEM (src.ptr (), 1 ), convert);
745
+ return first.load (seq[0 ], convert) && second.load (seq[1 ], convert);
746
746
}
747
747
748
748
static handle cast (const type &src, return_value_policy policy, handle parent) {
@@ -779,9 +779,12 @@ template <typename... Tuple> class type_caster<std::tuple<Tuple...>> {
779
779
780
780
public:
781
781
bool load (handle src, bool convert) {
782
- if (!src || !PyTuple_Check (src.ptr ()) || PyTuple_GET_SIZE (src.ptr ()) != size)
782
+ if (!isinstance<sequence>(src))
783
+ return false ;
784
+ const auto seq = reinterpret_borrow<sequence>(src);
785
+ if (seq.size () != size)
783
786
return false ;
784
- return load_impl (src , convert, indices{});
787
+ return load_impl (seq , convert, indices{});
785
788
}
786
789
787
790
static handle cast (const type &src, return_value_policy policy, handle parent) {
@@ -800,11 +803,11 @@ template <typename... Tuple> class type_caster<std::tuple<Tuple...>> {
800
803
template <size_t ... Is>
801
804
type implicit_cast (index_sequence<Is...>) { return type (cast_op<Tuple>(std::get<Is>(value))...); }
802
805
803
- static constexpr bool load_impl (handle , bool , index_sequence<>) { return true ; }
806
+ static constexpr bool load_impl (const sequence & , bool , index_sequence<>) { return true ; }
804
807
805
808
template <size_t ... Is>
806
- bool load_impl (handle src , bool convert, index_sequence<Is...>) {
807
- for (bool r : {std::get<Is>(value).load (PyTuple_GET_ITEM (src. ptr (), Is) , convert)...})
809
+ bool load_impl (const sequence &seq , bool convert, index_sequence<Is...>) {
810
+ for (bool r : {std::get<Is>(value).load (seq[Is] , convert)...})
808
811
if (!r)
809
812
return false ;
810
813
return true ;
0 commit comments