Fix rich comparison against None objects. Closes #1757

This commit is contained in:
Matthew Honnibal 2018-01-15 15:51:25 +01:00
parent 9e413449f6
commit b904d81e9a
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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: