Repository: Mathics3/mathics-core (language: python)

Issue:
Exception in comparison

## Description

```Wo["x"]>0``` raises an exception:

```
File "mathics-core/mathics/builtin/testing_expressions/equality_inequality.py", line 94, in eval
    c = do_cmp(x, y)
  File "mathics-core/mathics/eval/testing_expressions.py", line 32, in do_cmp
    if s1.is_Float and s2.is_Float:
AttributeError: 'NoneType' object has no attribute 'is_Float'
```

This seems to happen only if one of the arguments is a String. For example,

* `Wo[3]>0`
* `Wo[f[x]]>0`

stays unevaluated, but

* `Wo[3, "x"]>0`
* `Wo[f["x"]]>0`

raise the exception.








Discussion / hints:

Fix patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 9c2a59f91..c233ec27a 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -47,7 +47,8 @@ Bugs
 * ``Switch[]`` involving ``Infinity`` Issue #956
 * ``Outer[]`` on ``SparseArray`` Issue #939
 * ``ArrayQ[]`` detects ``SparseArray`` PR #947
-
+* Numeric comparisons against expressions involving ``String``s (Issue #797).
+  
 Package updates
 +++++++++++++++
 


Test patch:
diff --git a/mathics/eval/testing_expressions.py b/mathics/eval/testing_expressions.py
index 503e20a60..c37bb0f6e 100644
--- a/mathics/eval/testing_expressions.py
+++ b/mathics/eval/testing_expressions.py
@@ -20,7 +20,11 @@ def do_cmp(x1, x2) -> Optional[int]:
             return None
 
     s1 = x1.to_sympy()
+    if s1 is None:
+        return None
     s2 = x2.to_sympy()
+    if s2 is None:
+        return None
 
     # Use internal comparisons only for Real which is uses
     # WL's interpretation of equal (which allows for slop
diff --git a/test/builtin/test_comparison.py b/test/builtin/test_comparison.py
index 386b3123d..a2fc847c6 100644
--- a/test/builtin/test_comparison.py
+++ b/test/builtin/test_comparison.py
@@ -78,6 +78,14 @@
         ("g[a]<g[a]", "g[a] < g[a]", "not comparable expressions (like in WMA)"),
         ("g[1]<g[1]", "g[1] < g[1]", "not comparable expressions (like in WMA)"),
         #
+        ('Wo["x"]>3', "Wo[x] > 3", "isue #797"),
+        ('Wo["x"]<3', "Wo[x] < 3", "isue #797"),
+        ('Wo["x"]==3', "Wo[x] == 3", "isue #797"),
+        ('3>Wo["x"]', "3 > Wo[x]", "isue #797"),
+        ('3<Wo["x"]', "3 < Wo[x]", "isue #797"),
+        ('3==Wo["x"]', "3 == Wo[x]", "isue #797"),
+        ('Wo[f["x"],2]>0', "Wo[f[x], 2] > 0", "isue #797"),
+        #
         # chained compare
         ("a != a != b", "False", "Strange MMA behavior"),
         ("a != b != a", "a != b != a", "incomparable values should be unchanged"),