Fix assertion failures in super_attr

micropython: ../../py/objtype.c:1100: super_attr: Assertion `MP_OBJ_IS_TYPE(self->type, &mp_type_type)' failed.

e.g., when making calls like
    super(1, 1).x
This commit is contained in:
Jeff Epler 2018-03-25 16:13:49 -05:00 committed by Jeff Epler
parent 6da8d7c465
commit ff06a45599
2 changed files with 10 additions and 0 deletions

View File

@ -1085,6 +1085,9 @@ STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size
// 0 arguments are turned into 2 in the compiler
// 1 argument is not yet implemented
mp_arg_check_num(n_args, n_kw, 2, 2, false);
if(!MP_OBJ_IS_TYPE(args[0], &mp_type_type)) {
mp_raise_TypeError("first argument to super() must be type");
}
mp_obj_super_t *o = m_new_obj(mp_obj_super_t);
*o = (mp_obj_super_t){{type_in}, args[0], args[1]};
return MP_OBJ_FROM_PTR(o);

View File

@ -34,3 +34,10 @@ class B(A):
print(super().bar) # accessing attribute after super()
return super().foo().count(2) # calling a subsequent method
print(B().foo())
try:
super(1, 1).x
except TypeError:
print(True)
else:
print(False)