From e58f6dd967a7b3cd01624a1906a7338dfe62c70b Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sun, 31 Jan 2010 02:25:08 -0800 Subject: [PATCH] Method binding tests for #494. --- tests/run/function_binding_T494.pyx | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/run/function_binding_T494.pyx diff --git a/tests/run/function_binding_T494.pyx b/tests/run/function_binding_T494.pyx new file mode 100644 index 00000000..6823eecb --- /dev/null +++ b/tests/run/function_binding_T494.pyx @@ -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 -- 2.26.2