Commit f8735fb8 authored by Stefan Behnel's avatar Stefan Behnel

make auto_cpdef play nicely with stararg functions

parent 472549a1
...@@ -2032,6 +2032,17 @@ class DefNode(FuncDefNode): ...@@ -2032,6 +2032,17 @@ class DefNode(FuncDefNode):
api = False, api = False,
directive_locals = getattr(cfunc, 'directive_locals', {})) directive_locals = getattr(cfunc, 'directive_locals', {}))
def is_cdef_func_compatible(self):
"""Determines if the function's signature is compatible with a
cdef function. This can be used before calling
.as_cfunction() to see if that will be successful.
"""
if self.needs_closure:
return False
if self.star_arg or self.starstar_arg:
return False
return True
def analyse_declarations(self, env): def analyse_declarations(self, env):
self.is_classmethod = self.is_staticmethod = False self.is_classmethod = self.is_staticmethod = False
if self.decorators: if self.decorators:
......
...@@ -1425,9 +1425,8 @@ class AlignFunctionDefinitions(CythonTransform): ...@@ -1425,9 +1425,8 @@ class AlignFunctionDefinitions(CythonTransform):
error(pxd_def.pos, "previous declaration here") error(pxd_def.pos, "previous declaration here")
return None return None
node = node.as_cfunction(pxd_def) node = node.as_cfunction(pxd_def)
elif (self.scope.is_module_scope elif (self.scope.is_module_scope and self.directives['auto_cpdef']
and not node.needs_closure and node.is_cdef_func_compatible()):
and self.directives['auto_cpdef']):
node = node.as_cfunction(scope=self.scope) node = node.as_cfunction(scope=self.scope)
# Enable this when nested cdef functions are allowed. # Enable this when nested cdef functions are allowed.
# self.visitchildren(node) # self.visitchildren(node)
......
...@@ -22,3 +22,18 @@ def call_str(arg): ...@@ -22,3 +22,18 @@ def call_str(arg):
STR STR
""" """
return str(arg) return str(arg)
def stararg_func(*args):
"""
>>> stararg_func(1, 2)
(1, 2)
"""
return args
def starstararg_func(**kwargs):
"""
>>> starstararg_func(a=1)
1
"""
return kwargs['a']
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