Skip to content

Commit

Permalink
Remove support for anonymous objects.
Browse files Browse the repository at this point in the history
Anonymous objects were initially implemented as a way of failing
gracefully in the case when no explicit name was supplied.  However, an
anonymous object does not make much sense.
  • Loading branch information
scolobb committed Jun 15, 2012
1 parent bdef398 commit c60d285
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 31 deletions.
18 changes: 6 additions & 12 deletions sympy/categories/baseclasses.py
Expand Up @@ -21,40 +21,34 @@ class Object(Basic):
While concrete categories may have some concrete SymPy classes as
object types, in abstract categories only the name of an object is
known.
known. Anonymous objects are not allowed.
Two objects with the same name are the same object. An unnamed
object is not equal to any other object.
Two objects with the same name are the same object.
Examples
========
>>> from sympy.categories import Object
>>> Object("A") == Object("A")
True
>>> Object("A") == Object("")
False
"""
def __init__(self, name=""):
def __init__(self, name):
if not name:
raise ValueError("Anonymous Objects are not allowed.")

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

return self.name != obj.name

def __hash__(self):
Expand Down
4 changes: 2 additions & 2 deletions sympy/categories/tests/test_baseclasses.py
Expand Up @@ -9,13 +9,13 @@ def test_object():

assert A == Object("A")
assert A != Object("A1")
assert Object("") != A
assert Object("") != Object("")

assert hash(A) == hash(Object("A"))

assert A != None

raises(ValueError, lambda: Object(""))

def test_morphism():
A = Object("A")
B = Object("B")
Expand Down
5 changes: 1 addition & 4 deletions sympy/printing/latex.py
Expand Up @@ -1182,10 +1182,7 @@ def _print_DMF(self, p):
return self._print_DMP(p)

def _print_Object(self, object):
if object.name:
return self._print(Symbol(object.name))
else:
return "\\bullet"
return self._print(Symbol(object.name))

def _print_Morphism(self, morphism):
domain = self._print(morphism.domain)
Expand Down
8 changes: 1 addition & 7 deletions sympy/printing/pretty/pretty.py
Expand Up @@ -1447,13 +1447,7 @@ def _print_DMF(self, p):
return self._print_DMP(p)

def _print_Object(self, object):
if object.name:
return self._print(pretty_symbol(object.name))
else:
if self._use_unicode:
return self._print(u"\u2022")
else:
return self._print(".")
return self._print(pretty_symbol(object.name))

def _print_Morphism(self, morphism):
arrow = "->"
Expand Down
5 changes: 1 addition & 4 deletions sympy/printing/pretty/tests/test_pretty.py
Expand Up @@ -3718,10 +3718,7 @@ def test_categories():
assert pretty(K1) == "K1"
assert upretty(K1) == u"K₁"

# Some further tests for anonymous objects and morphisms.
assert pretty(Object("")) == "."
assert upretty(Object("")) == u"•"

# Some further tests for anonymous morphisms.
h = Morphism(A2, A3, "").compose(Morphism(A1, A2, ""), "h")
assert pretty(h) == "h:A1->A3"
assert upretty(h) == u"h:A₁→A₃"
Expand Down
2 changes: 0 additions & 2 deletions sympy/printing/tests/test_latex.py
Expand Up @@ -589,8 +589,6 @@ def test_categories():

assert latex(K1) == "\mathbf{K_{1}}"

assert latex(Object("")) == "\\bullet"

h = Morphism(A2, A3, "").compose(Morphism(A1, A2, ""), "h")
assert latex(h) == "h:A_{1}\\rightarrow A_{3}"

Expand Down

0 comments on commit c60d285

Please sign in to comment.