Skip to content

Commit ff06a45

Browse files
committed
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
1 parent 6da8d7c commit ff06a45

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

py/objtype.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,9 @@ STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size
10851085
// 0 arguments are turned into 2 in the compiler
10861086
// 1 argument is not yet implemented
10871087
mp_arg_check_num(n_args, n_kw, 2, 2, false);
1088+
if(!MP_OBJ_IS_TYPE(args[0], &mp_type_type)) {
1089+
mp_raise_TypeError("first argument to super() must be type");
1090+
}
10881091
mp_obj_super_t *o = m_new_obj(mp_obj_super_t);
10891092
*o = (mp_obj_super_t){{type_in}, args[0], args[1]};
10901093
return MP_OBJ_FROM_PTR(o);

tests/basics/class_super.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ def foo(self):
3434
print(super().bar) # accessing attribute after super()
3535
return super().foo().count(2) # calling a subsequent method
3636
print(B().foo())
37+
38+
try:
39+
super(1, 1).x
40+
except TypeError:
41+
print(True)
42+
else:
43+
print(False)

0 commit comments

Comments
 (0)