diff --git a/spacy/tokens/span.pyx b/spacy/tokens/span.pyx index 10b8a7820..7c8e0a9ed 100644 --- a/spacy/tokens/span.pyx +++ b/spacy/tokens/span.pyx @@ -64,6 +64,11 @@ cdef class Span: self._vector_norm = vector_norm def __richcmp__(self, Span other, int op): + if other is None: + if op == 0 or op == 1 or op == 2: + return False + else: + return True # Eq if op == 0: return self.start_char < other.start_char diff --git a/spacy/tokens/token.pyx b/spacy/tokens/token.pyx index 281c0a4be..11a165ab8 100644 --- a/spacy/tokens/token.pyx +++ b/spacy/tokens/token.pyx @@ -78,10 +78,15 @@ cdef class Token: def __richcmp__(self, Token other, int op): # http://cython.readthedocs.io/en/latest/src/userguide/special_methods.html + if other is None: + if op in (0, 1, 2): + return False + else: + return True cdef Doc my_doc = self.doc cdef Doc other_doc = other.doc my = self.idx - their = other.idx if other is not None else None + their = other.idx if op == 0: return my < their elif op == 2: