Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 7dda4ac

Browse files
committed
Use richcmp_item to compare Word_class
1 parent 9dde00f commit 7dda4ac

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/sage/combinat/words/abstract_word.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from itertools import islice, groupby
4141
from sage.rings.all import Integers, ZZ, Infinity
4242
from sage.structure.richcmp import (richcmp_method, rich_to_bool,
43-
richcmp, op_LT, op_GT)
43+
richcmp_item)
4444

4545

4646
@richcmp_method
@@ -75,7 +75,6 @@ def _repr_(self):
7575
sage: Word(lambda x:x%3)._repr_()
7676
'word: 0120120120120120120120120120120120120120...'
7777
"""
78-
global word_options
7978
if word_options['old_repr']:
8079
return "Word over %s" % (str(self.parent().alphabet())[17:])
8180
return word_options['identifier'] + self.string_rep()
@@ -122,7 +121,6 @@ def string_rep(self):
122121
sage: print(w)
123122
0123401234012340123401234012340123401234...
124123
"""
125-
global word_options
126124
l = word_options['truncate_length']
127125
letters = list(islice(self, int(l + 1)))
128126
if len(letters) == l + 1:
@@ -374,10 +372,9 @@ def __richcmp__(self, other, op):
374372
else:
375373
key_cs = cmp_key(cs)
376374
key_co = cmp_key(co)
377-
if key_cs < key_co:
378-
return rich_to_bool(op, -1)
379-
elif key_cs > key_co:
380-
return rich_to_bool(op, 1)
375+
res = richcmp_item(key_cs, key_co, op)
376+
if res is not NotImplemented:
377+
return res
381378

382379
def _longest_common_prefix_iterator(self, other):
383380
r"""
@@ -705,7 +702,7 @@ def lex_less(self, other):
705702
sage: t[:10].lex_less(t)
706703
True
707704
"""
708-
return richcmp(self, other, op_LT)
705+
return self < other
709706

710707
def lex_greater(self, other):
711708
r"""
@@ -735,7 +732,7 @@ def lex_greater(self, other):
735732
sage: t.lex_greater(t[:10])
736733
True
737734
"""
738-
return richcmp(self, other, op_GT)
735+
return self > other
739736

740737
def apply_morphism(self, morphism):
741738
r"""

0 commit comments

Comments
 (0)