From 8c51fd4d89f010dfde89c7296d4e76238cfa4ba8 Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Thu, 12 Oct 2023 08:10:57 +0200 Subject: [PATCH] Preserve previous behavior for None --- spacy/tests/doc/test_doc_api.py | 4 ++-- spacy/tokens/span.pyx | 4 ++-- spacy/tokens/token.pyx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spacy/tests/doc/test_doc_api.py b/spacy/tests/doc/test_doc_api.py index a1b936085..73544c51a 100644 --- a/spacy/tests/doc/test_doc_api.py +++ b/spacy/tests/doc/test_doc_api.py @@ -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 diff --git a/spacy/tokens/span.pyx b/spacy/tokens/span.pyx index bb320ea1b..e179bbce7 100644 --- a/spacy/tokens/span.pyx +++ b/spacy/tokens/span.pyx @@ -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) diff --git a/spacy/tokens/token.pyx b/spacy/tokens/token.pyx index 5abae55db..2ed736b70 100644 --- a/spacy/tokens/token.pyx +++ b/spacy/tokens/token.pyx @@ -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