Method binding tests for #494.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sun, 31 Jan 2010 10:25:08 +0000 (02:25 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sun, 31 Jan 2010 10:25:08 +0000 (02:25 -0800)
tests/run/function_binding_T494.pyx [new file with mode: 0644]

diff --git a/tests/run/function_binding_T494.pyx b/tests/run/function_binding_T494.pyx
new file mode 100644 (file)
index 0000000..6823eec
--- /dev/null
@@ -0,0 +1,36 @@
+cimport cython
+
+class SomeNumber(object):
+
+    def __init__(self, n):
+        self._n = n
+    
+    def __repr__(self):
+        return "SomeNumber(%s)" % self._n
+
+@cython.binding(True)
+def add_to_func(self, x):
+    """
+    >>> add_to_func(SomeNumber(2), 5)
+    7
+    >>> SomeNumber(3).add_to(10)
+    13
+    >>> SomeNumber.add_to(SomeNumber(22), 7)
+    29
+    """
+    return self._n + x
+
+@cython.binding(False)
+def new_num(n):
+    """
+    >>> new_num(11)
+    SomeNumber(11)
+    >>> SomeNumber.new(11)
+    SomeNumber(11)
+    >>> SomeNumber(3).new(11)
+    SomeNumber(11)
+    """
+    return SomeNumber(n)
+
+SomeNumber.add_to = add_to_func
+SomeNumber.new = new_num