forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathsubclass_native.py
52 lines (34 loc) · 1010 Bytes
/
subclass_native.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
try:
NativeBaseClass
except NameError:
print("SKIP")
raise SystemExit
# This tests two things that CircuitPython uses:
# 1. Native class's `make_new` get kwargs.
# 2. Native class's properties get used instead of creating a new attribute on
# the subclass instance.
n = NativeBaseClass(test="direct kwarg")
print(".test:", n.test)
n.test = "test set directly"
print(".test:", n.test)
class A(NativeBaseClass):
pass
a = A(test="subclass kwarg")
print(".test:", a.test)
a.test = "test set indirectly"
print(".test:", a.test)
a.new_attribute = True
print(".new_attribute", a.new_attribute)
a.print_subclass_attr("new_attribute")
print(a[0])
class B(NativeBaseClass):
def __init__(self, suffix):
super().__init__(test="super init " + suffix)
b = B("suffix")
print(".test:", b.test)
b.test = "test set indirectly through b"
print(".test:", b.test)
b.new_attribute = "hello"
print(".new_attribute", b.new_attribute)
b.print_subclass_attr("new_attribute")
print(b[0])