self.operand.analyse_types(env)
to_py = self.type.is_pyobject
from_py = self.operand.type.is_pyobject
- if from_py and not to_py and self.operand.is_ephemeral() and not self.type.is_numeric:
- error(self.pos, "Casting temporary Python object to non-numeric non-Python type")
+ if from_py and not to_py and self.operand.is_ephemeral():
+ if not self.type.is_numeric and not self.type.is_cpp_class:
+ error(self.pos, "Casting temporary Python object to non-numeric non-Python type")
if to_py and not from_py:
if self.type is bytes_type and self.operand.type.is_int:
# FIXME: the type cast node isn't needed in this case
cdef string s = o.encode('ascii')
return s
+def test_encode_to_string_cast(o):
+ """
+ >>> normalize(test_encode_to_string_cast('abc'))
+ 'abc'
+ >>> normalize(test_encode_to_string_cast('abc\\x00def'))
+ 'abc\\x00def'
+ """
+ s = <string>o.encode('ascii')
+ return s
+
def test_bytes_encode_to_string(bytes o):
"""
>>> normalize(test_bytes_encode_to_string('abc'))