summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/subclass_native1.py
blob: 74b377eac91b919dbd176cc8655b68acb522c916 (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
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)

# subclassing a type that doesn't have make_new at the C level (not allowed)
try:
    class myfunc(type([].append)):
        pass
except TypeError:
    print("TypeError")

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