From d1c5392eceddd830feb5c0bcba2e50e87c880e5a Mon Sep 17 00:00:00 2001 From: Haoyu Bai Date: Thu, 7 Apr 2011 20:55:35 +0800 Subject: [PATCH] fix cdef @locals with default arguments --- Cython/Compiler/Nodes.py | 7 ++++++- tests/run/cdef_locals_decorator_T477.pyx | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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) -- 2.26.2