summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/subclass-native1.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-30 21:02:50 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-30 21:02:50 +0100
commit37977b7b27a293aa6ae10726203d81aa0f074566 (patch)
treeae6bc99631f9db55c8f611af117a2413b6b51d46 /tests/basics/subclass-native1.py
parent4ae52d454c211d151f0ebf6b13d0a4a14ee1563d (diff)
parentc963310123765baddf638c8d08b8fdb2f73b6ba6 (diff)
downloadmicropython-37977b7b27a293aa6ae10726203d81aa0f074566.tar.gz
micropython-37977b7b27a293aa6ae10726203d81aa0f074566.zip
Merge pull request #528 from pfalcon/native-subclass1
Initial support for subclassing native types
Diffstat (limited to 'tests/basics/subclass-native1.py')
-rw-r--r--tests/basics/subclass-native1.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/basics/subclass-native1.py b/tests/basics/subclass-native1.py
new file mode 100644
index 0000000000..a176893425
--- /dev/null
+++ b/tests/basics/subclass-native1.py
@@ -0,0 +1,31 @@
+class mylist(list):
+ pass
+
+a = mylist([1, 2, 5])
+# Test setting instance attr
+a.attr = "something"
+# Test base type __str__
+print(a)
+# Test getting instance attr
+print(a.attr)
+# Test base type ->subscr
+print(a[-1])
+a[0] = -1
+print(a)
+# Test another base type unary op
+print(len(a))
+
+# Test binary op of base type, with 2nd arg being raw base type
+print(a + [20, 30, 40])
+# Test binary op of base type, with 2nd arg being same class as 1st arg
+# TODO: Faults
+#print(a + a)
+
+def foo():
+ print("hello from foo")
+
+try:
+ class myfunc(type(foo)):
+ pass
+except TypeError:
+ print("TypeError")