From 3baf2bfdb9bc048e376f0f326ae9ed18323ea850 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 11 Feb 2010 23:42:14 +0100 Subject: [PATCH] minor fix and extension to type inference for builtin type operations --- Cython/Compiler/ExprNodes.py | 8 +++++--- tests/run/type_inference.pyx | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index b4f0a695..7be86a8d 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -4766,10 +4766,12 @@ class BinopNode(ExprNode): return type1 # multiplication of containers/numbers with an # integer value always (?) returns the same type - if type1.is_int: - return type2 - elif type2.is_int: + if type2.is_int: return type1 + elif type2.is_builtin_type and type1.is_int and self.operator == '*': + # multiplication of containers/numbers with an + # integer value always (?) returns the same type + return type2 return py_object_type else: return self.compute_c_result_type(type1, type2) diff --git a/tests/run/type_inference.pyx b/tests/run/type_inference.pyx index b545902e..315c826f 100644 --- a/tests/run/type_inference.pyx +++ b/tests/run/type_inference.pyx @@ -104,10 +104,12 @@ def builtin_type_operations(): >>> builtin_type_operations() """ b1 = b'a' * 10 + b1 = 10 * b'a' assert typeof(b1) == "bytes object", typeof(b1) b2 = b'a' + b'b' assert typeof(b2) == "bytes object", typeof(b2) u1 = u'a' * 10 + u1 = 10 * u'a' assert typeof(u1) == "unicode object", typeof(u1) u2 = u'a' + u'b' assert typeof(u2) == "unicode object", typeof(u2) -- 2.26.2