Merged pull request #12 from bhy/T423.
[cython.git] / tests / run / builtin_type_inheritance_T608.pyx
index dcf04fe6fc125409a305b5bba0c0360e79475db0..af80dae67be82f863f15aebd1e529c9cc20c1ef7 100644 (file)
@@ -1,3 +1,4 @@
+# ticket: 608
 
 cdef class MyInt(int):
     """
@@ -8,6 +9,35 @@ cdef class MyInt(int):
     """
     cdef readonly object attr
 
+cdef class MyInt2(int):
+    """
+    >>> MyInt2(2) == 2
+    True
+    >>> MyInt2(2).attr is None
+    True
+    >>> MyInt2(2).test(3)
+    5
+    """
+    cdef readonly object attr
+
+    def test(self, arg):
+        return self._test(arg)
+
+    cdef _test(self, arg):
+        return self + arg
+
+cdef class MyInt3(MyInt2):
+    """
+    >>> MyInt3(2) == 2
+    True
+    >>> MyInt3(2).attr is None
+    True
+    >>> MyInt3(2).test(3)
+    6
+    """
+    cdef _test(self, arg):
+        return self + arg + 1
+
 cdef class MyFloat(float):
     """
     >>> MyFloat(1.0)== 1.0
@@ -23,6 +53,8 @@ cdef class MyUnicode(unicode):
     """
     >>> MyUnicode(ustring) == ustring
     True
+    >>> MyUnicode(ustring + ustring) == ustring
+    False
     >>> MyUnicode(ustring).attr is None
     True
     """
@@ -37,6 +69,43 @@ cdef class MyList(list):
     """
     cdef readonly object attr
 
+cdef class MyListOverride(list):
+    """
+    >>> MyListOverride([1,2,3]) == [1,2,3]
+    True
+    >>> l = MyListOverride([1,2,3])
+    >>> l.reverse()
+    >>> l
+    [1, 2, 3, 5]
+    >>> l._reverse()
+    >>> l
+    [1, 2, 3, 5, 5]
+    """
+    # not doctested:
+    """
+    >>> l = MyListOverride([1,2,3])
+    >>> l.append(8)
+    >>> l
+    [1, 2, 3, 0, 8]
+    >>> l._append(9)
+    >>> l
+    [1, 2, 3, 0, 8, 0, 9]
+    """
+    def reverse(self):
+        self[:] = self + [5]
+
+    def _reverse(self):
+        self.reverse()
+
+    ## FIXME: this doesn't currently work:
+
+    ## cdef int append(self, value) except -1:
+    ##     self[:] = self + [0] + [value]
+    ##     return 0
+
+    ## def _append(self, value):
+    ##     self.append(value)
+
 cdef class MyDict(dict):
     """
     >>> MyDict({1:2, 3:4}) == {1:2, 3:4}