py/objtype: Allow mp_instance_cast_to_native_base to take native obj.

And rename it to mp_obj_cast_to_native_base() to indicate this.  This
allows users of this function to easily support native and native-subclass
objects in the same way (by just passing the object through this function).
This commit is contained in:
Damien George
2020-02-21 13:15:21 +11:00
parent d3b2c6e44c
commit 9344e876bb
3 changed files with 10 additions and 6 deletions

View File

@@ -109,7 +109,7 @@ STATIC mp_obj_t tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t anothe
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
if (another_type->getiter != mp_obj_tuple_getiter) {
// Slow path for user subclasses
another_in = mp_instance_cast_to_native_base(another_in, MP_OBJ_FROM_PTR(&mp_type_tuple));
another_in = mp_obj_cast_to_native_base(another_in, MP_OBJ_FROM_PTR(&mp_type_tuple));
if (another_in == MP_OBJ_NULL) {
return MP_OBJ_NULL;
}