Preserve previous behavior for None

This commit is contained in:
Adriane Boyd 2023-10-12 08:10:57 +02:00
parent 40d7512ce6
commit 8c51fd4d89
3 changed files with 6 additions and 6 deletions

View File

@ -61,10 +61,10 @@ def test_issue1757():
doc = Doc(Vocab(), words=["a", "b", "c"])
assert not doc[0] < None
assert not doc[0] is None
assert not doc[0] == None
assert doc[0] >= None
assert not doc[:2] < None
assert not doc[:2] is None
assert not doc[:2] == None
assert doc[:2] >= None
assert not doc.vocab["a"] is None
assert not doc.vocab["a"] < None

View File

@ -128,13 +128,13 @@ cdef class Span:
self._vector_norm = vector_norm
def __richcmp__(self, object other, int op):
if not isinstance(other, Span):
return False
if other is None:
if op == 0 or op == 1 or op == 2:
return False
else:
return True
if not isinstance(other, Span):
return False
cdef Span other_span = other
self_tuple = (self.c.start_char, self.c.end_char, self.c.label, self.c.kb_id, self.id, self.doc)
other_tuple = (other_span.c.start_char, other_span.c.end_char, other_span.c.label, other_span.c.kb_id, other_span.id, other_span.doc)

View File

@ -140,14 +140,14 @@ cdef class Token:
return self.__str__()
def __richcmp__(self, object other, int op):
if not isinstance(other, Token):
return False
# 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
if not isinstance(other, Token):
return False
cdef Token other_token = other
cdef Doc my_doc = self.doc
cdef Doc other_doc = other_token.doc