]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Clarify comment about `@cython.binding`.
authorBen Darnell <ben@bendarnell.com>
Tue, 15 Sep 2015 00:29:53 +0000 (20:29 -0400)
committerBen Darnell <ben@bendarnell.com>
Tue, 15 Sep 2015 00:29:53 +0000 (20:29 -0400)
It's only necessary for static functions, not methods.

maint/test/cython/cythonapp.pyx
maint/test/cython/cythonapp_test.py
tornado/util.py

index 0539a22899dc1daa6cac67d80f3fd57c6965c4bd..54d20661e84c198f037cc313d1e2fcbbcb906548 100644 (file)
@@ -16,7 +16,14 @@ def decorated_coroutine():
     return "goodbye"
 
 # The binding directive is necessary for compatibility with
-# ArgReplacer (and therefore return_future).
+# ArgReplacer (and therefore return_future), but only because
+# this is a static function.
 @cython.binding(True)
 def function_with_args(one, two, three):
     return (one, two, three)
+
+
+class AClass:
+    # methods don't need the binding directive.
+    def method_with_args(one, two, three):
+        return (one, two, three)
index 975194ebd93a40cc22f452bbba5b1b94b5f93668..c3312de41da36d6d756b10822d8279d6481eb12f 100644 (file)
@@ -25,10 +25,18 @@ class CythonCoroutineTest(AsyncTestCase):
 
 
 class CythonArgReplacerTest(unittest.TestCase):
-    def test_arg_replacer(self):
+    def test_arg_replacer_function(self):
         replacer = ArgReplacer(cythonapp.function_with_args, 'two')
         args = (1, 'old', 3)
         kwargs = {}
         self.assertEqual(replacer.get_old_value(args, kwargs), 'old')
         self.assertEqual(replacer.replace('new', args, kwargs),
                          ('old', [1, 'new', 3], {}))
+
+    def test_arg_replacer_method(self):
+        replacer = ArgReplacer(cythonapp.AClass().method_with_args, 'two')
+        args = (1, 'old', 3)
+        kwargs = {}
+        self.assertEqual(replacer.get_old_value(args, kwargs), 'old')
+        self.assertEqual(replacer.replace('new', args, kwargs),
+                         ('old', [1, 'new', 3], {}))
index ce5362dc0812636c10032b3b6980036119db2833..a67ddf50db5a0d90187bcc4a2962d40868a2dc53 100644 (file)
@@ -301,10 +301,11 @@ class ArgReplacer(object):
         except TypeError:
             if hasattr(func, 'func_code'):
                 # Cython-generated code has all the attributes needed
-                # by inspect.getargspec (when the
-                # @cython.binding(True) directive is used), but the
-                # inspect module only works with ordinary functions.
-                # Inline the portion of getargspec that we need here.
+                # by inspect.getargspec, but the inspect module only
+                # works with ordinary functions. Inline the portion of
+                # getargspec that we need here. Note that for static
+                # functions the @cython.binding(True) decorator must
+                # be used (for methods it works out of the box).
                 code = func.func_code
                 return code.co_varnames[:code.co_argcount]
             raise