do not generate vtable for subtypes of builtin types that do not define methods thems...
[cython.git] / tests / run / builtin_type_inheritance_T608.pyx
1
2 cdef class MyInt(int):
3     """
4     >>> MyInt(2) == 2
5     True
6     >>> MyInt(2).attr is None
7     True
8     """
9     cdef readonly object attr
10
11 cdef class MyInt2(int):
12     """
13     >>> MyInt2(2) == 2
14     True
15     >>> MyInt2(2).attr is None
16     True
17     >>> MyInt2(2).test(3)
18     5
19     """
20     cdef readonly object attr
21
22     def test(self, arg):
23         return self._test(arg)
24
25     cdef _test(self, arg):
26         return self + arg
27
28 cdef class MyInt3(MyInt2):
29     """
30     >>> MyInt3(2) == 2
31     True
32     >>> MyInt3(2).attr is None
33     True
34     >>> MyInt3(2).test(3)
35     6
36     """
37     cdef _test(self, arg):
38         return self + arg + 1
39
40 cdef class MyFloat(float):
41     """
42     >>> MyFloat(1.0)== 1.0
43     True
44     >>> MyFloat(1.0).attr is None
45     True
46     """
47     cdef readonly object attr
48
49 ustring = u'abc'
50
51 cdef class MyUnicode(unicode):
52     """
53     >>> MyUnicode(ustring) == ustring
54     True
55     >>> MyUnicode(ustring + ustring) == ustring
56     False
57     >>> MyUnicode(ustring).attr is None
58     True
59     """
60     cdef readonly object attr
61
62 cdef class MyList(list):
63     """
64     >>> MyList([1,2,3]) == [1,2,3]
65     True
66     >>> MyList([1,2,3]).attr is None
67     True
68     """
69     cdef readonly object attr
70
71 cdef class MyListOverride(list):
72     """
73     >>> MyListOverride([1,2,3]) == [1,2,3]
74     True
75     >>> l = MyListOverride([1,2,3])
76     >>> l.reverse()
77     >>> l
78     [1, 2, 3, 5]
79     >>> l._reverse()
80     >>> l
81     [1, 2, 3, 5, 5]
82     """
83     # not doctested:
84     """
85     >>> l = MyListOverride([1,2,3])
86     >>> l.append(8)
87     >>> l
88     [1, 2, 3, 0, 8]
89     >>> l._append(9)
90     >>> l
91     [1, 2, 3, 0, 8, 0, 9]
92     """
93     def reverse(self):
94         self[:] = self + [5]
95
96     def _reverse(self):
97         self.reverse()
98
99     ## FIXME: this doesn't currently work:
100
101     ## cdef int append(self, value) except -1:
102     ##     self[:] = self + [0] + [value]
103     ##     return 0
104
105     ## def _append(self, value):
106     ##     self.append(value)
107
108 cdef class MyDict(dict):
109     """
110     >>> MyDict({1:2, 3:4}) == {1:2, 3:4}
111     True
112     >>> MyDict({1:2, 3:4}).attr is None
113     True
114     """
115     cdef readonly object attr