Commit 714f5e86 authored by Stefan Behnel's avatar Stefan Behnel

fix (doc-)string usage in .pxd files

parent a45f2ef2
......@@ -182,5 +182,6 @@ cdef p_c_class_definition(PyrexScanner s, pos, ctx)
cdef p_c_class_options(PyrexScanner s)
cdef p_property_decl(PyrexScanner s)
cdef p_doc_string(PyrexScanner s)
cdef p_ignorable_statement(PyrexScanner s)
cdef p_compiler_directive_comments(PyrexScanner s)
cdef p_cpp_class_definition(PyrexScanner s, pos, ctx)
......@@ -1894,8 +1894,9 @@ def p_statement(s, ctx, first_statement = 0):
return p_pass_statement(s, with_newline=True)
else:
if ctx.level in ('c_class_pxd', 'property'):
if s.sy == 'BEGIN_STRING':
return p_atom(s) # allow docstrings and discardable strings
node = p_ignorable_statement(s)
if node is not None:
return node
s.error("Executable statement not allowed here")
if s.sy == 'if':
return p_if_statement(s)
......@@ -3081,6 +3082,19 @@ def p_property_decl(s):
return Nodes.PropertyNode(pos, name=name, doc=doc, body=body)
def p_ignorable_statement(s):
"""
Parses any kind of ignorable statement that is allowed in .pxd files.
"""
if s.sy == 'BEGIN_STRING':
pos = s.position()
string_node = p_atom(s)
if s.sy != 'EOF':
s.expect_newline("Syntax error in string")
return Nodes.ExprStatNode(pos, expr=string_node)
return None
def p_doc_string(s):
if s.sy == 'BEGIN_STRING':
pos = s.position()
......
PYTHON setup.py build_ext --inplace
PYTHON -c "import a; a.test()"
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize("a.pyx"),
)
######## a.pyx ########
cdef class ExtTypeDocstringPass:
pass
cdef class ExtTypeDocstring:
"huhu!" # this should override the .pxd docstring
cdef class ExtTypePass:
pass
cdef class ExtTypeDocstringPassString:
pass
def test():
assert not ExtTypePass().__doc__, ExtTypePass().__doc__
assert ExtTypeDocstring().__doc__ == "huhu!", ExtTypeDocstring().__doc__
assert ExtTypeDocstringPass().__doc__ == "hoho!", ExtTypeDocstringPass().__doc__
assert ExtTypeDocstringPassString().__doc__ == "hoho!", ExtTypeDocstringPassString().__doc__
######## a.pxd ########
cdef class ExtTypePass:
pass
cdef class ExtTypeDocstring:
"""
hoho
"""
cdef class ExtTypeDocstringPass:
"hoho!"
pass
cdef class ExtTypeDocstringPassString:
"hoho!"
pass
"more hoho"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment