fix #683: allow overriding C-API mapped builtin functions with (auto-)cpdef functions
authorStefan Behnel <scoder@users.berlios.de>
Wed, 13 Apr 2011 19:25:03 +0000 (21:25 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 13 Apr 2011 19:25:03 +0000 (21:25 +0200)
Cython/Compiler/ParseTreeTransforms.py
tests/run/auto_cpdef.py [new file with mode: 0644]

index e004852e5e430a51b30153c9d71a035aabaf381e..1e9cf7b12fe7c73f08897fa3ccdf9bfc58417f00 100644 (file)
@@ -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 (file)
index 0000000..bd6da41
--- /dev/null
@@ -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)