diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index e1adc9e88b6..b73bb67341e 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1039,13 +1039,18 @@ def coerce_to(self, dst_type, env): pass elif src.constant_result is None: src = NoneNode(src.pos).coerce_to(dst_type, env) - elif not src.type.is_pyobject: - if dst_type is bytes_type and src.type.is_int: - src = CoerceIntToBytesNode(src, env) - else: - src = CoerceToPyTypeNode(src, env, type=dst_type) - elif not src.type.subtype_of(dst_type): - src = PyTypeTestNode(src, dst_type, env) + else: + if not src.type.is_pyobject: + if dst_type is bytes_type and src.type.is_int: + src = CoerceIntToBytesNode(src, env) + else: + src = CoerceToPyTypeNode(src, env, type=dst_type) + # FIXME: I would expect that CoerceToPyTypeNode(type=dst_type) returns a value of type dst_type + # but it doesn't for ctuples. Thus, we add a PyTypeTestNode which then triggers the + # Python conversion and becomes useless. That sems backwards and inefficient. + # We should not need a PyTypeTestNode after a previous conversion above. + if not src.type.subtype_of(dst_type): + src = PyTypeTestNode(src, dst_type, env) elif is_pythran_expr(dst_type) and is_pythran_supported_type(src.type): # We let the compiler decide whether this is valid return src