Commit df367231 authored by Stefan Behnel's avatar Stefan Behnel

fix crash in staticmethods without explicit positional argument (ticket 804)

parent 7741822f
......@@ -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,
......
......@@ -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()))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment