summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/subclass_native1.py
blob: 288a686d1a75691e0a9d9ef3d247cfed667737c2 (plain) (blame)
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
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")

# multiple bases with layout conflict
try:
    class A(type, tuple):
        None
except TypeError:
    print('TypeError')