|
44 | 44 | #define ENABLE_SPECIAL_ACCESSORS \
|
45 | 45 | (MICROPY_PY_DESCRIPTORS || MICROPY_PY_DELATTR_SETATTR || MICROPY_PY_BUILTINS_PROPERTY)
|
46 | 46 |
|
| 47 | +static mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo); |
47 | 48 | static mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
48 | 49 |
|
49 | 50 | /******************************************************************************/
|
@@ -1260,9 +1261,15 @@ static mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size
|
1260 | 1261 | // 0 arguments are turned into 2 in the compiler
|
1261 | 1262 | // 1 argument is not yet implemented
|
1262 | 1263 | mp_arg_check_num(n_args, n_kw, 2, 2, false);
|
1263 |
| - if (!mp_obj_is_type(args[0], &mp_type_type)) { |
| 1264 | + |
| 1265 | + // Per CPython: "If the second argument is an object, isinstance(obj, type) must be true. |
| 1266 | + // If the second argument is a type, issubclass(type2, type) must be true (this is useful for classmethods)." |
| 1267 | + const mp_obj_type_t *second_arg_type = mp_obj_get_type(args[1]); |
| 1268 | + mp_obj_t second_arg_obj = second_arg_type == &mp_type_type ? args[1] : MP_OBJ_FROM_PTR(second_arg_type); |
| 1269 | + if (mp_obj_is_subclass(second_arg_obj, args[0]) == mp_const_false) { |
1264 | 1270 | mp_raise_TypeError(NULL);
|
1265 | 1271 | }
|
| 1272 | + |
1266 | 1273 | mp_obj_super_t *o = m_new_obj(mp_obj_super_t);
|
1267 | 1274 | *o = (mp_obj_super_t) {{type_in}, args[0], args[1]};
|
1268 | 1275 | return MP_OBJ_FROM_PTR(o);
|
|
0 commit comments