From: Haoyu Bai Date: Thu, 7 Apr 2011 12:55:35 +0000 (+0800) Subject: fix cdef @locals with default arguments X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d1c5392eceddd830feb5c0bcba2e50e87c880e5a;p=cython.git fix cdef @locals with default arguments --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index a8ed64e6..b8f94cee 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1673,7 +1673,12 @@ class CFuncDefNode(FuncDefNode): self.directive_locals.update(env.directives['locals']) base_type = self.base_type.analyse(env) # The 2 here is because we need both function and argument names. - name_declarator, type = self.declarator.analyse(base_type, env, nonempty = 2 * (self.body is not None)) + if isinstance(self.declarator, CFuncDeclaratorNode): + name_declarator, type = self.declarator.analyse(base_type, env, + nonempty = 2 * (self.body is not None), + directive_locals = self.directive_locals) + else: + name_declarator, type = self.declarator.analyse(base_type, env, nonempty = 2 * (self.body is not None)) if not type.is_cfunction: error(self.pos, "Suite attached to non-function declaration") diff --git a/tests/run/cdef_locals_decorator_T477.pyx b/tests/run/cdef_locals_decorator_T477.pyx index c495fc91..617f011a 100644 --- a/tests/run/cdef_locals_decorator_T477.pyx +++ b/tests/run/cdef_locals_decorator_T477.pyx @@ -5,6 +5,10 @@ import cython cdef func(x): return x**2 +@cython.locals(x=double) +cdef func_defval(x=0): + return x**2 + def test(): """ >>> isinstance(test(), float)