diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index b4f0a695c57ae4c54dbfbbfe412edbab415336e4..7be86a8d224c8b886a4ec673dbbd62c6fef25584 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 b545902e0972ff674fbc3290f6b9894cf0dd2365..315c826fddb1413ba5e07b2bc26b26c158a50074 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)