support None as compile time constant expression
authorStefan Behnel <stefan_ml@behnel.de>
Wed, 13 Feb 2013 19:00:46 +0000 (20:00 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Wed, 13 Feb 2013 19:00:46 +0000 (20:00 +0100)
Cython/Compiler/Parsing.py
tests/errors/nonconst_def_tuple.pyx
tests/run/ct_DEF.pyx

index a17aae3..779c3b4 100644 (file)
@@ -691,7 +691,9 @@ def p_name(s, name):
 
 def wrap_compile_time_constant(pos, value):
     rep = repr(value)
-    if isinstance(value, bool):
+    if value is None:
+        return ExprNodes.NoneNode(pos)
+    elif isinstance(value, bool):
         return ExprNodes.BoolNode(pos, value=value)
     elif isinstance(value, int):
         return ExprNodes.IntNode(pos, value=rep)
index 89d6aeb..9f247ee 100644 (file)
@@ -8,6 +8,5 @@ x = t_non_const
 
 _ERRORS = u"""
 5:32: Error in compile-time expression: IndexError: tuple index out of range
-7:15: Invalid type for compile-time constant: None (type NoneType)
 7:15: Invalid type for compile-time constant: [1, 2, 3] (type list)
 """
index 485f3ef..3ca0298 100644 (file)
@@ -13,6 +13,7 @@ if sys.version_info[0] < 3:
 
 DEF TUPLE = (1, 2, u"buckle my shoe")
 DEF TRUE_FALSE = (True, False)
+DEF NONE = None
 
 DEF CHAR = c'x'
 DEF INT0 = -1
@@ -156,3 +157,9 @@ def expression():
     """
     cdef int i = EXPRESSION
     return i
+
+def none():
+    """
+    >>> none()
+    """
+    return NONE