From b3bbfb4c2e084d702214431dafce2c0a4b57f985 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Fri, 17 Oct 2008 09:44:59 +0200 Subject: [PATCH] Docstring bugfix (#103) --- Cython/Compiler/Parsing.py | 6 ++++-- tests/run/r_docstrings.pyx | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 8ef8277a..45fa1015 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -2401,14 +2401,16 @@ def p_compiler_directive_comments(s): def p_module(s, pxd, full_module_name): pos = s.position() + + option_comments = p_compiler_directive_comments(s) + s.parse_comments = False + doc = p_doc_string(s) if pxd: level = 'module_pxd' else: level = 'module' - option_comments = p_compiler_directive_comments(s) - s.parse_comments = False body = p_statement_list(s, Ctx(level = level), first_statement = 1) if s.sy != 'EOF': s.error("Syntax error in statement [%s,%s]" % ( diff --git a/tests/run/r_docstrings.pyx b/tests/run/r_docstrings.pyx index 60508fbe..00a9fdad 100644 --- a/tests/run/r_docstrings.pyx +++ b/tests/run/r_docstrings.pyx @@ -1,4 +1,14 @@ -__doc__ = u"""# Python 3 gets all of these right ... +# Some comments first + + +# More comments + +'A module docstring' + +doctest = u"""# Python 3 gets all of these right ... + >>> __doc__ + 'A module docstring' + >>> f.__doc__ 'This is a function docstring.' @@ -38,7 +48,9 @@ Compare with standard Python: import sys if sys.version_info[0] >= 3: - __doc__ = __doc__.replace(u" u'", u" '") + doctest = doctest.replace(u" u'", u" '") + +__test__ = {"test_docstrings" : doctest} def f(): u"This is a function docstring." -- 2.26.2