summaryrefslogtreecommitdiff
path: root/tests/run/builtin_type_inheritance_T608_py2only.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run/builtin_type_inheritance_T608_py2only.pyx')
-rw-r--r--tests/run/builtin_type_inheritance_T608_py2only.pyx42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/run/builtin_type_inheritance_T608_py2only.pyx b/tests/run/builtin_type_inheritance_T608_py2only.pyx
new file mode 100644
index 000000000..b10a2610a
--- /dev/null
+++ b/tests/run/builtin_type_inheritance_T608_py2only.pyx
@@ -0,0 +1,42 @@
+# ticket: t608
+
+# This only works reliably in Python2. In Python3 ints are variable-sized.
+# You get away with it for small ints but it's a bad idea
+
+cdef class MyInt(int):
+ """
+ >>> MyInt(2) == 2
+ True
+ >>> MyInt(2).attr is None
+ True
+ """
+ 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