summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@unpythonic.net>2018-03-25 16:13:49 -0500
committerJeff Epler <jepler@gmail.com>2018-03-29 06:42:10 -0500
commitff06a455995322978dbd9ad9291154ebbdf0abb5 (patch)
tree10151a20c72514253de9d7cb3027a73ec0440ed6
parent6da8d7c46583387aa32d5c153b3c5b7d9e1afccd (diff)
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
-rw-r--r--py/objtype.c3
-rw-r--r--tests/basics/class_super.py7
2 files changed, 10 insertions, 0 deletions
diff --git a/py/objtype.c b/py/objtype.c
index 3fa25eb77..5b70e8e48 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -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);
diff --git a/tests/basics/class_super.py b/tests/basics/class_super.py
index 1338ef452..5a18017ac 100644
--- a/tests/basics/class_super.py
+++ b/tests/basics/class_super.py
@@ -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)