Skip to content

Commit d94d82f

Browse files
committed
KeyCompariable() generalization on == and !=
1 parent 18ea818 commit d94d82f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

mathics/core/expression.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ def __ge__(self, other) -> bool:
137137
return self.get_sort_key() >= other.get_sort_key()
138138

139139
def __eq__(self, other) -> bool:
140-
return self.get_sort_key() == other.get_sort_key()
140+
return hasattr(other, "get_sort_key") and self.get_sort_key() == other.get_sort_key()
141141

142142
def __ne__(self, other) -> bool:
143-
return self.get_sort_key() != other.get_sort_key()
143+
return (not hasattr(other, "get_sort_key")) or self.get_sort_key() != other.get_sort_key()
144144

145145

146146
# ExpressionCache keeps track of the following attributes for one Expression instance:
@@ -2635,7 +2635,10 @@ def __new__(cls, value):
26352635
self = super(StringFromPython, cls).__new__(cls, value)
26362636
if isinstance(value, sympy.NumberSymbol):
26372637
self.value = "sympy." + str(value)
2638-
elif value == math.inf:
2638+
2639+
# Note that the test is done with math.inf first.
2640+
# This is to use float's ==, which may not strictly be necessary.
2641+
if math.inf == value:
26392642
self.value = "math.inf"
26402643
return self
26412644

0 commit comments

Comments
 (0)