Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
714f5e86
Commit
714f5e86
authored
Jan 13, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix (doc-)string usage in .pxd files
parent
a45f2ef2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
2 deletions
+68
-2
Cython/Compiler/Parsing.pxd
Cython/Compiler/Parsing.pxd
+1
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+16
-2
tests/run/pxd_syntax.srctree
tests/run/pxd_syntax.srctree
+51
-0
No files found.
Cython/Compiler/Parsing.pxd
View file @
714f5e86
...
...
@@ -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
)
Cython/Compiler/Parsing.py
View file @
714f5e86
...
...
@@ -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
()
...
...
tests/run/pxd_syntax.srctree
0 → 100644
View file @
714f5e86
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"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment