From d817949dec34f0b66ba730b8c8eb75bffdea1da3 Mon Sep 17 00:00:00 2001 From: Craig Citro Date: Wed, 7 Jul 2010 01:11:24 -0700 Subject: [PATCH] Fix an error with coercing C ints in boolean context. --- Cython/Compiler/ExprNodes.py | 7 ++++++- tests/run/boolean_context.pyx | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/run/boolean_context.pyx diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 852286f4..7239c635 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -6268,7 +6268,12 @@ class CoerceToPyTypeNode(CoercionNode): return False def coerce_to_boolean(self, env): - return self.arg.coerce_to_boolean(env).coerce_to_temp(env) + arg_type = self.arg.type + if (arg_type == PyrexTypes.c_bint_type or + (arg_type.is_pyobject and arg_type.name == 'bool')): + return self.arg.coerce_to_temp(env) + else: + return CoerceToBooleanNode(self, env) def coerce_to_integer(self, env): # If not already some C integer type, coerce to longint. diff --git a/tests/run/boolean_context.pyx b/tests/run/boolean_context.pyx new file mode 100644 index 00000000..f6d59e1b --- /dev/null +++ b/tests/run/boolean_context.pyx @@ -0,0 +1,8 @@ + +def test(): + """ + >>> test() + True + """ + cdef int x = 5 + print bool(x) -- 2.26.2