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
6005320d
Commit
6005320d
authored
Aug 15, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Give a better parser error message when defining cdef modifiers on def functions.
See #2529.
parent
271d2505
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
12 deletions
+39
-12
Cython/Compiler/Parsing.pxd
Cython/Compiler/Parsing.pxd
+1
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+16
-4
tests/errors/def_nogil.pyx
tests/errors/def_nogil.pyx
+0
-8
tests/errors/invalid_syntax_py.pyx
tests/errors/invalid_syntax_py.pyx
+22
-0
No files found.
Cython/Compiler/Parsing.pxd
View file @
6005320d
...
...
@@ -182,6 +182,7 @@ cdef p_c_modifiers(PyrexScanner s)
cdef
p_c_func_or_var_declaration
(
PyrexScanner
s
,
pos
,
ctx
)
cdef
p_ctypedef_statement
(
PyrexScanner
s
,
ctx
)
cdef
p_decorators
(
PyrexScanner
s
)
cdef
_reject_cdef_modifier_in_py
(
PyrexScanner
s
,
name
)
cdef
p_def_statement
(
PyrexScanner
s
,
list
decorators
=*
,
bint
is_async_def
=*
)
cdef
p_varargslist
(
PyrexScanner
s
,
terminator
=*
,
bint
annotated
=
*
)
cdef
p_py_arg_decl
(
PyrexScanner
s
,
bint
annotated
=
*
)
...
...
Cython/Compiler/Parsing.py
View file @
6005320d
...
...
@@ -13,7 +13,8 @@ cython.declare(Nodes=object, ExprNodes=object, EncodedString=object,
Future
=
object
,
Options
=
object
,
error
=
object
,
warning
=
object
,
Builtin
=
object
,
ModuleNode
=
object
,
Utils
=
object
,
_unicode
=
object
,
_bytes
=
object
,
re
=
object
,
sys
=
object
,
_parse_escape_sequences
=
object
,
_parse_escape_sequences_raw
=
object
,
partial
=
object
,
reduce
=
object
,
_IS_PY3
=
cython
.
bint
,
_IS_2BYTE_UNICODE
=
cython
.
bint
)
partial
=
object
,
reduce
=
object
,
_IS_PY3
=
cython
.
bint
,
_IS_2BYTE_UNICODE
=
cython
.
bint
,
_CDEF_MODIFIERS
=
tuple
)
from
io
import
StringIO
import
re
...
...
@@ -35,6 +36,7 @@ from . import Options
_IS_PY3
=
sys
.
version_info
[
0
]
>=
3
_IS_2BYTE_UNICODE
=
sys
.
maxunicode
==
0xffff
_CDEF_MODIFIERS
=
(
'inline'
,
'nogil'
,
'api'
)
class
Ctx
(
object
):
...
...
@@ -3350,6 +3352,16 @@ def p_decorators(s):
return
decorators
def
_reject_cdef_modifier_in_py
(
s
,
name
):
"""Step over incorrectly placed cdef modifiers (@see _CDEF_MODIFIERS) to provide a good error message for them.
"""
if
s
.
sy
==
'IDENT'
and
name
in
_CDEF_MODIFIERS
:
# Special enough to provide a good error message.
s
.
error
(
"Cannot use cdef modifier '%s' in Python function signature. Use a decorator instead."
%
name
,
fatal
=
False
)
return
p_ident
(
s
)
# Keep going, in case there are other errors.
return
name
def
p_def_statement
(
s
,
decorators
=
None
,
is_async_def
=
False
):
# s.sy == 'def'
pos
=
s
.
position
()
...
...
@@ -3357,16 +3369,16 @@ def p_def_statement(s, decorators=None, is_async_def=False):
if
is_async_def
:
s
.
enter_async
()
s
.
next
()
name
=
p_ident
(
s
)
name
=
_reject_cdef_modifier_in_py
(
s
,
p_ident
(
s
)
)
s
.
expect
(
'('
)
args
,
star_arg
,
starstar_arg
=
p_varargslist
(
s
,
terminator
=
')'
)
s
.
expect
(
')'
)
if
p_nogil
(
s
):
error
(
pos
,
"Python function cannot be declared nogil"
)
_reject_cdef_modifier_in_py
(
s
,
s
.
systring
)
return_type_annotation
=
None
if
s
.
sy
==
'->'
:
s
.
next
()
return_type_annotation
=
p_test
(
s
)
_reject_cdef_modifier_in_py
(
s
,
s
.
systring
)
doc
,
body
=
p_suite_with_docstring
(
s
,
Ctx
(
level
=
'function'
))
if
is_async_def
:
...
...
tests/errors/def_nogil.pyx
deleted
100644 → 0
View file @
271d2505
# mode: error
def
test
()
nogil
:
pass
_ERRORS
=
"""
3:0: Python function cannot be declared nogil
"""
tests/errors/invalid_syntax_py.pyx
0 → 100644
View file @
6005320d
# mode: error
# tag: syntax
def
inline
func
()
->
int
:
pass
def
api
func
()
->
int
:
pass
def
nogil
func
()
->
int
:
pass
def
func
()
nogil
:
pass
_ERRORS
=
u"""
4:11: Cannot use cdef modifier 'inline' in Python function signature. Use a decorator instead.
7:8: Cannot use cdef modifier 'api' in Python function signature. Use a decorator instead.
10:10: Cannot use cdef modifier 'nogil' in Python function signature. Use a decorator instead.
13:11: Cannot use cdef modifier 'nogil' in Python function signature. Use a decorator instead.
"""
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