Commit c0440965 authored by Mark Florisson's avatar Mark Florisson

Provide better error message when memoryview data cannot be converted to object

parent bd673cc3
...@@ -2548,7 +2548,6 @@ class IndexNode(ExprNode): ...@@ -2548,7 +2548,6 @@ class IndexNode(ExprNode):
warning(index.pos, "Index should be typed for more " warning(index.pos, "Index should be typed for more "
"efficient access", level=2) "efficient access", level=2)
IndexNode.warned_untyped_idx = True IndexNode.warned_untyped_idx = True
elif index.type.is_int:
self.memslice_index = True self.memslice_index = True
index = index.coerce_to(index_type, env) index = index.coerce_to(index_type, env)
indices[i] = index indices[i] = index
......
...@@ -341,10 +341,13 @@ cdef class memoryview(object): ...@@ -341,10 +341,13 @@ cdef class memoryview(object):
cdef bytes bytesitem cdef bytes bytesitem
# Do a manual and complete check here instead of this easy hack # Do a manual and complete check here instead of this easy hack
bytesitem = itemp[:self.view.itemsize] bytesitem = itemp[:self.view.itemsize]
try:
result = struct.unpack(self.view.format, bytesitem) result = struct.unpack(self.view.format, bytesitem)
except struct.error:
raise ValueError("Unable to convert item to object")
else:
if len(self.view.format) == 1: if len(self.view.format) == 1:
return result[0] return result[0]
return result return result
cdef assign_item_from_object(self, char *itemp, object value): cdef assign_item_from_object(self, char *itemp, object value):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment