From: Stefan Behnel Date: Sat, 16 Feb 2008 17:37:23 +0000 (+0100) Subject: fixes for True/False in compile time expressions; make sure True/False pass as object... X-Git-Tag: 0.9.6.14~29^2~22^2~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=595c2453e4cb23e9bcd3c46d80aa5eb9cf34bee9;p=cython.git fixes for True/False in compile time expressions; make sure True/False pass as objects (not just ints) where possible --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index a2299a61..c613959b 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -489,7 +489,7 @@ class ExprNode(Node): src = CoerceFromPyTypeNode(dst_type, src, env) else: # neither src nor dst are py types # Added the string comparison, since for c types that - # is enough, but SageX gets confused when the types are + # is enough, but Cython gets confused when the types are # in different files. if not (str(src.type) == str(dst_type) or dst_type.assignable_from(src_type)): error(self.pos, "Cannot assign type '%s' to '%s'" % @@ -588,7 +588,7 @@ class BoolNode(PyConstNode): def coerce_to(self, dst_type, env): value = self.value if dst_type.is_numeric: - return IntNode(self.pos, value=self.value).coerce_to(dst_type, env) + return IntNode(self.pos, value=int(self.value)).coerce_to(dst_type, env) else: return PyConstNode.coerce_to(self, dst_type, env) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index a430a0c9..7a9444c4 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -469,9 +469,9 @@ def p_atom(s): if name == "None": return ExprNodes.NoneNode(pos) elif name == "True": - return ExprNodes.BoolNode(pos, value=1) + return ExprNodes.BoolNode(pos, value=True) elif name == "False": - return ExprNodes.BoolNode(pos, value=0) + return ExprNodes.BoolNode(pos, value=False) else: return p_name(s, name) elif sy == 'NULL': @@ -489,7 +489,9 @@ def p_name(s, name): pass else: rep = repr(value) - if isinstance(value, int): + if isinstance(value, bool): + return ExprNodes.BoolNode(pos, value = value) + elif isinstance(value, int): return ExprNodes.IntNode(pos, value = rep) elif isinstance(value, long): return ExprNodes.LongNode(pos, value = rep)