[Pyrex] cdef docstrings

Eric Huss e-huss at netmeridian.com
Fri Jun 2 17:06:56 UTC 2006


Attached are two patches that try to allow the user to enter a docstring
for cdef functions, but not have them included in the resulting compiled
code.  patch_with_doc is more specialized in that it only excludes
docstrings for cdef functions.  patch_string_expression is more
generalized in that any standalone string expression anywhere in your
Pyrex code will get optimized out (I have not tested this very thoroughly
and I'm also not a fan of using triple quoted strings to comment out code,
so I ended up not using it, but I'm including it in case someone else is
interested).

-Eric
-------------- next part --------------
--- Parsing.py.orig	Sat Apr 15 02:18:48 2006
+++ Parsing.py	Thu Jun  1 09:15:20 2006
@@ -650,7 +650,10 @@
         expr_list.append(p_expr(s))
     if len(expr_list) == 1:
         expr = expr_list[0]
-        return Nodes.ExprStatNode(expr.pos, expr = expr)
+        if isinstance(expr, ExprNodes.StringNode):
+            return Nodes.PassStatNode(expr.pos)
+        else:
+            return Nodes.ExprStatNode(expr.pos, expr = expr)
     else:
         expr_list_list = []
         flatten_parallel_assignments(expr_list, expr_list_list)
-------------- next part --------------
--- Parsing.py.orig	Sat Apr 15 02:18:48 2006
+++ Parsing.py	Thu Jun  1 09:14:26 2006
@@ -1568,7 +1568,8 @@
     if s.sy == ':':
         if level not in ('module', 'c_class'):
             s.error("C function definition not allowed here")
-        suite = p_suite(s, 'function')
+        doc, suite = p_suite(s, 'function', with_doc = 1)
+        # Discarding the doc value since C functions don't have docstrings.
         result = Nodes.CFuncDefNode(pos,
             visibility = visibility,
             base_type = base_type,


More information about the Pyrex mailing list