Commit bc43abf7 authored by Stefan Behnel's avatar Stefan Behnel

Add a deprecation warning to usages of the compile time "IF" statement.

See https://github.com/cython/cython/issues/4310
parent 76e888e2
...@@ -2303,6 +2303,10 @@ def p_statement(s, ctx, first_statement = 0): ...@@ -2303,6 +2303,10 @@ def p_statement(s, ctx, first_statement = 0):
elif s.sy == 'DEF': elif s.sy == 'DEF':
return p_DEF_statement(s) return p_DEF_statement(s)
elif s.sy == 'IF': elif s.sy == 'IF':
warning(s.position(),
"The 'IF' statement is deprecated and will be removed in a future Cython version. "
"Consider using runtime conditions or C macros instead. "
"See https://github.com/cython/cython/issues/4310", level=1)
return p_IF_statement(s, ctx) return p_IF_statement(s, ctx)
elif s.sy == '@': elif s.sy == '@':
if ctx.level not in ('module', 'class', 'c_class', 'function', 'property', 'module_pxd', 'c_class_pxd', 'other'): if ctx.level not in ('module', 'class', 'c_class', 'function', 'property', 'module_pxd', 'c_class_pxd', 'other'):
......
# mode: run
# tag: warnings
DEF NO = 0 DEF NO = 0
DEF YES = 1 DEF YES = 1
...@@ -72,3 +75,12 @@ def control_flow_DEF2(): ...@@ -72,3 +75,12 @@ def control_flow_DEF2():
DEF B=3 DEF B=3
print('B should be 3.') print('B should be 3.')
return B return B
_WARNINGS = """
13:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
27:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
41:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
56:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
71:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
"""
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