summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-19 00:47:40 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-19 00:47:40 +0000
commitebde0b8a095653ed3073cf821c44e91ec0897a41 (patch)
treec26de632e09ec92ccb4816fd5ba062d6c34b90dd
parenta8a6db2a1ddffc9c1f5c9894ac5837ec3bc7c025 (diff)
downloadmicropython-ebde0b8a095653ed3073cf821c44e91ec0897a41.tar.gz
micropython-ebde0b8a095653ed3073cf821c44e91ec0897a41.zip
Tiny optimisation in objlist.c; a new test for inheritance.
-rw-r--r--py/objlist.c6
-rw-r--r--tests/basics/tests/class_inherit1.py21
2 files changed, 24 insertions, 3 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 4822c7b684..e499d94239 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -44,16 +44,16 @@ static mp_obj_t list_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
switch (n_args) {
case 0:
// return a new, empty list
- return rt_build_list(0, NULL);
+ return mp_obj_new_list(0, NULL);
case 1:
{
// make list from iterable
mp_obj_t iterable = rt_getiter(args[0]);
- mp_obj_t list = rt_build_list(0, NULL);
+ mp_obj_t list = mp_obj_new_list(0, NULL);
mp_obj_t item;
while ((item = rt_iternext(iterable)) != mp_const_stop_iteration) {
- rt_list_append(list, item);
+ mp_obj_list_append(list, item);
}
return list;
}
diff --git a/tests/basics/tests/class_inherit1.py b/tests/basics/tests/class_inherit1.py
new file mode 100644
index 0000000000..9ca2d9f14b
--- /dev/null
+++ b/tests/basics/tests/class_inherit1.py
@@ -0,0 +1,21 @@
+class A:
+ def __init__(self, x):
+ print('A init', x)
+ self.x = x
+
+ def f(self):
+ print(self.x, self.y)
+
+class B(A):
+ def __init__(self, x, y):
+ A.__init__(self, x)
+ print('B init', x, y)
+ self.y = y
+
+ def g(self):
+ print(self.x, self.y)
+
+A(1)
+b = B(1, 2)
+b.f()
+b.g()