From c6df93716bb6121f478bd6f02c11baafbc85743e Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Tue, 21 Jul 2009 09:21:32 -0400
Subject: [PATCH] Prohibit expression comparison.

---
 pymbolic/primitives.py |  6 ++++++
 test/test_pymbolic.py  | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py
index 9f10859..4615731 100644
--- a/pymbolic/primitives.py
+++ b/pymbolic/primitives.py
@@ -185,6 +185,12 @@ class Expression(object):
     def get_hash(self):
         raise NotImplementedError("get_hash() in "+str(type(self)))
 
+    # comparison interface ----------------------------------------------------
+    def __le__(self, other): raise TypeError("expressions don't have an order")
+    def __lt__(self, other): raise TypeError("expressions don't have an order")
+    def __ge__(self, other): raise TypeError("expressions don't have an order")
+    def __gt__(self, other): raise TypeError("expressions don't have an order")
+
 
 
 
diff --git a/test/test_pymbolic.py b/test/test_pymbolic.py
index 7b8e97a..715d4a7 100644
--- a/test/test_pymbolic.py
+++ b/test/test_pymbolic.py
@@ -107,3 +107,24 @@ def test_sparse_multiply():
     mat_vec_2 = csr_matrix_multiply(s_mat, vec)
 
     assert la.norm(mat_vec-mat_vec_2) < 1e-14
+
+
+
+def test_no_comparison():
+    from pymbolic import parse
+
+    x = parse("17+3*x") 
+    y = parse("12-5*y")
+
+    def expect_typeerror(f):
+        try:
+            f()
+        except TypeError:
+            pass
+        else:
+            assert False
+
+    expect_typeerror(lambda: x < y)
+    expect_typeerror(lambda: x <= y)
+    expect_typeerror(lambda: x > y)
+    expect_typeerror(lambda: x >= y)
-- 
GitLab