* 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
1 changed files with 4 additions and 1 deletions

View File

@ -68,7 +68,10 @@ cdef class Token:
cdef inline Token cinit(Vocab vocab, unicode string, cdef inline Token cinit(Vocab vocab, unicode string,
const TokenC* token, int offset, int array_len, const TokenC* token, int offset, int array_len,
list py_tokens, tuple tag_strings, tuple dep_strings): 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: if py_tokens[offset] is not None:
return py_tokens[offset] return py_tokens[offset]