From d229fbd228a14996ab5600c6062e2b2c3dabdb0b Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 7 Feb 2015 12:59:12 -0500 Subject: [PATCH] * Give better error on out-of-bounds array access --- spacy/tokens.pxd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spacy/tokens.pxd b/spacy/tokens.pxd index 8f8564a83..88acfa8c6 100644 --- a/spacy/tokens.pxd +++ b/spacy/tokens.pxd @@ -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]