Commit 7f9c0dca authored by Stefan Behnel's avatar Stefan Behnel

Provide a better error message when users accidentally write Cython code in a .py file.

Closes #1824.
parent 7e4f2ac0
......@@ -2149,7 +2149,14 @@ def p_simple_statement_list(s, ctx, first_statement = 0):
stat = stats[0]
else:
stat = Nodes.StatListNode(pos, stats = stats)
if s.sy not in ('NEWLINE', 'EOF'):
# provide a better error message for users who accidentally write Cython code in .py files
if isinstance(stat, Nodes.ExprStatNode):
if stat.expr.is_name and stat.expr.name == 'cdef':
s.error("The 'cdef' keyword is only allowed in Cython files (pyx/pxi/pxd)", pos)
s.expect_newline("Syntax error in simple statement list")
return stat
def p_compile_time_expr(s):
......
# mode: error
def func():
cdef int i
_ERRORS = """
4:9: The 'cdef' keyword is only allowed in Cython files (pyx/pxi/pxd)
"""
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