From: Dag Sverre Seljebotn Date: Mon, 5 Oct 2009 13:04:47 +0000 (+0200) Subject: Fix doctesthack for cdef functions X-Git-Tag: 0.13.beta0~2^2~123^2~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3f00253b0e169e389538fb824dbcdc4157638588;p=cython.git Fix doctesthack for cdef functions --- diff --git a/Cython/Compiler/AnalysedTreeTransforms.py b/Cython/Compiler/AnalysedTreeTransforms.py index 355c50c7..b8f45086 100644 --- a/Cython/Compiler/AnalysedTreeTransforms.py +++ b/Cython/Compiler/AnalysedTreeTransforms.py @@ -1,5 +1,5 @@ from Cython.Compiler.Visitor import VisitorTransform, ScopeTrackingTransform, TreeVisitor -from Nodes import StatListNode, SingleAssignmentNode +from Nodes import StatListNode, SingleAssignmentNode, CFuncDefNode from ExprNodes import (DictNode, DictItemNode, NameNode, UnicodeNode, NoneNode, ExprNode, AttributeNode, ModuleRefNode, DocstringRefNode) from PyrexTypes import py_object_type @@ -53,6 +53,10 @@ class DoctestHackTransform(ScopeTrackingTransform): def visit_FuncDefNode(self, node): if node.doc: + if isinstance(node, CFuncDefNode) and not node.py_func: + # skip non-cpdef cdef functions + return node + pos = self.testspos if self.scope_type == 'module': parent = ModuleRefNode(pos) @@ -69,6 +73,8 @@ class DoctestHackTransform(ScopeTrackingTransform): is_py_attr=True, is_temp=True) name = "%s.%s" % (clsname, node.entry.name) + else: + assert False getfunc = AttributeNode(pos, obj=parent, attribute=node.entry.name, type=py_object_type, diff --git a/tests/run/doctesthack.pyx b/tests/run/doctesthack.pyx index 2a97b556..32b982f5 100644 --- a/tests/run/doctesthack.pyx +++ b/tests/run/doctesthack.pyx @@ -1,4 +1,4 @@ -#cython: doctesthack=True +# Directive defaults to True """ Tests doctesthack compiler directive. @@ -12,17 +12,25 @@ all_tests_run() is executed which does final validation. >>> items.sort() >>> for key, value in items: ... print key, ';', value -MyCdefClass.method (line 67) ; >>> add_log("cdef class method") -MyClass.method (line 57) ; >>> add_log("class method") -doc_without_test (line 39) ; Some docs -mycpdeffunc (line 45) ; >>> add_log("cpdef") -myfunc (line 36) ; >>> add_log("def") +MyCdefClass.method (line 75) ; >>> add_log("cdef class method") +MyClass.method (line 65) ; >>> add_log("class method") +doc_without_test (line 47) ; Some docs +mycpdeffunc (line 53) ; >>> add_log("cpdef") +myfunc (line 44) ; >>> add_log("def") """ log = [] +cdef cdeffunc(): + """ + Please don't include me! + + >>> True + False + """ + def all_tests_run(): log.sort() assert log == [u'cdef class method', u'class method', u'cpdef', u'def'], log