Permalink
Browse files

Make Morphism and Object check for the type of the other object in co…

…mparisons.

Objects of these classes would previously throw exceptions when compared
to something improper (like None).
  • Loading branch information...
1 parent 7fcee70 commit 207ee8a883e80a57873919b2b722543c27941408 @scolobb committed Jun 6, 2012
Showing with 13 additions and 0 deletions.
  1. +9 −0 sympy/categories/baseclasses.py
  2. +4 −0 sympy/categories/tests/test_baseclasses.py
@@ -41,12 +41,18 @@ def __init__(self, name=""):
self.name = name
def __eq__(self, obj):
+ if not isinstance(obj, Object):
+ return False
+
if (not obj.name) or (not self.name):
return False
return self.name == obj.name
def __ne__(self, obj):
+ if not isinstance(obj, Object):
+ return True
+
if (not obj.name) or (not self.name):
return True
@@ -207,6 +213,9 @@ def flatten(self, new_name=""):
return Morphism(self.domain, self.codomain, new_name)
def __eq__(self, g):
+ if not isinstance(g, Morphism):
+ return False
+
if self.identity and g.identity:
# All identities are equal.
return self.domain == g.domain
@@ -14,6 +14,8 @@ def test_object():
assert hash(A) == hash(Object("A"))
+ assert A != None
+
def test_morphism():
A = Object("A")
B = Object("B")
@@ -29,6 +31,8 @@ def test_morphism():
assert f.codomain == B
assert f.components == [f]
+ assert f != None
+
assert f * g == None
assert f * f == None

0 comments on commit 207ee8a

Please sign in to comment.