fix crash in staticmethods without explicit positional argument (ticket 804)
authorStefan Behnel <stefan_ml@behnel.de>
Sun, 17 Mar 2013 07:44:21 +0000 (08:44 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Sun, 17 Mar 2013 07:44:21 +0000 (08:44 +0100)
Cython/Compiler/Nodes.py
tests/run/staticmethod.pyx

index 06be08a..adb00ab 100644 (file)
@@ -2630,7 +2630,7 @@ class DefNode(FuncDefNode):
 
         if self.is_staticmethod and env.is_c_class_scope:
             nfixed = 0
-            self.self_in_stararg = True
+            self.self_in_stararg = True  # FIXME: why for staticmethods?
 
             self.entry.signature = sig = copy.copy(sig)
             sig.fixed_arg_format = "*"
@@ -3162,7 +3162,7 @@ class DefNodeWrapper(FuncDefNode):
             self.starstar_arg.entry.xdecref_cleanup = 0
             code.put_gotref(self.starstar_arg.entry.cname)
 
-        if self.self_in_stararg:
+        if self.self_in_stararg and not self.target.is_staticmethod:
             # need to create a new tuple with 'self' inserted as first item
             code.put("%s = PyTuple_New(PyTuple_GET_SIZE(%s)+1); if (unlikely(!%s)) " % (
                     self.star_arg.entry.cname,
index 8227a7e..c3d6b74 100644 (file)
@@ -101,3 +101,22 @@ class SubSubClass(SubClass):
         print arg1
         super().mystaticmethod(self, arg1 + 1)
 
+
+cdef class ArgsKwargs(object):
+    @staticmethod
+    def with_first_arg(arg1, *args, **kwargs):
+        """
+        >>> ArgsKwargs().with_first_arg(1, 2, 3, a=4, b=5)
+        (1, 'pos', 2, 3, ('a', 4), ('b', 5))
+        """
+        return (arg1, 'pos') + args + tuple(sorted(kwargs.items()))
+
+    @staticmethod
+    def only_args_kwargs(*args, **kwargs):
+        """
+        >>> ArgsKwargs().only_args_kwargs()
+        ()
+        >>> ArgsKwargs().only_args_kwargs(1, 2, a=3)
+        (1, 2, ('a', 3))
+        """
+        return args + tuple(sorted(kwargs.items()))