From 327311c054d7e353c594a2bbb7bc12100c1fb931 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 13 Feb 2013 20:00:46 +0100 Subject: [PATCH] support None as compile time constant expression --- Cython/Compiler/Parsing.py | 4 +++- tests/errors/nonconst_def_tuple.pyx | 1 - tests/run/ct_DEF.pyx | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index a17aae3..779c3b4 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -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) diff --git a/tests/errors/nonconst_def_tuple.pyx b/tests/errors/nonconst_def_tuple.pyx index 89d6aeb..9f247ee 100644 --- a/tests/errors/nonconst_def_tuple.pyx +++ b/tests/errors/nonconst_def_tuple.pyx @@ -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) """ diff --git a/tests/run/ct_DEF.pyx b/tests/run/ct_DEF.pyx index 485f3ef..3ca0298 100644 --- a/tests/run/ct_DEF.pyx +++ b/tests/run/ct_DEF.pyx @@ -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 -- 2.7.4