* Give better error on out-of-bounds array access

This commit is contained in:
Matthew Honnibal 2015-02-07 12:59:12 -05:00
parent ab8bb047d0
commit d229fbd228

View File

@ -68,7 +68,10 @@ cdef class Token:
cdef inline Token cinit(Vocab vocab, unicode string,
const TokenC* token, int offset, int array_len,
list py_tokens, tuple tag_strings, tuple dep_strings):
assert offset >= 0 and offset < array_len
if offset < 0 or offset >= array_len:
msg = "Attempt to access token at %d, max length %d"
raise IndexError(msg % (offset, array_len))
if py_tokens[offset] is not None:
return py_tokens[offset]