From: Stefan Behnel Date: Wed, 13 Apr 2011 19:25:03 +0000 (+0200) Subject: fix #683: allow overriding C-API mapped builtin functions with (auto-)cpdef functions X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=368ddfc3a4c8ac95bc9aeb4cc2a2adfe1b45ee74;p=cython.git fix #683: allow overriding C-API mapped builtin functions with (auto-)cpdef functions --- diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index e004852e..1e9cf7b1 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -1418,7 +1418,7 @@ class AlignFunctionDefinitions(CythonTransform): def visit_DefNode(self, node): pxd_def = self.scope.lookup(node.name) - if pxd_def: + if pxd_def and (not pxd_def.scope or not pxd_def.scope.is_builtin_scope): if not pxd_def.is_cfunction: error(node.pos, "'%s' redeclared" % node.name) if pxd_def.pos: diff --git a/tests/run/auto_cpdef.py b/tests/run/auto_cpdef.py new file mode 100644 index 00000000..bd6da412 --- /dev/null +++ b/tests/run/auto_cpdef.py @@ -0,0 +1,24 @@ +# cython: auto_cpdef=True +# mode:run +# tag: directive,auto_cpdef + +import cython + +def str(arg): + """ + This is a bit evil - str gets mapped to a C-API function and is + being redefined here. + + >>> print(str('TEST')) + STR + """ + return 'STR' + +@cython.test_assert_path_exists('//SimpleCallNode[@function.type.is_cfunction = True]') +@cython.test_fail_if_path_exists('//SimpleCallNode[@function.type.is_builtin_type = True]') +def call_str(arg): + """ + >>> print(call_str('TEST')) + STR + """ + return str(arg)