Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make Object a direct descendent of Symbol.

This is because Object has essentially become a Symbol.  However, an
Object class is still needed in order to avoid the abuse of the name
"symbol".  Note that the printing routines have remained the same for
Object, for the sake of convenience.
  • Loading branch information...
commit d03d55c4d674c8a7c00b86e3057363badfe97082 1 parent 47d9af7
@scolobb authored
View
42 sympy/categories/baseclasses.py
@@ -16,44 +16,14 @@ class Class(Set):
"""
is_proper = False
-class Object(Basic):
+class Object(Symbol):
"""
The base class for any kind of object in an abstract category.
- While concrete categories may have some concrete SymPy classes as
- object types, in abstract categories only the name of an object is
- known. Anonymous objects are not allowed.
-
- Two objects with the same name are the same object.
-
- Examples
- ========
-
- >>> from sympy.categories import Object
- >>> Object("A") == Object("A")
- True
-
+ While technically any instance of :class:`Basic` will do, this
+ class is the recommended way to create abstract objects in
+ abstract categories.
"""
- def __new__(cls, name):
- if not name:
- raise ValueError("Anonymous Objects are not allowed.")
-
- return Basic.__new__(cls, Symbol(name))
-
- @property
- def name(self):
- """
- Returns the name of this object.
-
- Examples
- ========
- >>> from sympy.categories import Object
- >>> A = Object("A")
- >>> A.name
- 'A'
-
- """
- return self._args[0].name
class Morphism(Basic):
"""
@@ -588,7 +558,7 @@ class Diagram(Basic):
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g])
>>> print pretty(d.premises.keys(), use_unicode=False)
- [id:B->B, id:A->A, id:C->C, f:A->B, g*f:A->C, g:B->C]
+ [f:A->B, id:B->B, g*f:A->C, g:B->C, id:C->C, id:A->A]
>>> print pretty(d.premises, use_unicode=False)
{g*f:A->C: EmptySet(), id:A->A: EmptySet(), id:B->B: EmptySet(), id:C->C: Empt
ySet(), f:A->B: EmptySet(), g:B->C: EmptySet()}
@@ -812,7 +782,7 @@ def objects(self):
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g])
>>> d.objects
- {Object("B"), Object("C"), Object("A")}
+ {Object("C"), Object("B"), Object("A")}
"""
return self.args[2]
View
14 sympy/categories/tests/test_baseclasses.py
@@ -5,20 +5,6 @@
from sympy.utilities.pytest import XFAIL, raises
from sympy import FiniteSet, EmptySet, Dict, Tuple
-def test_object():
- A = Object("A")
-
- assert A.name == "A"
-
- assert A == Object("A")
- assert A != Object("A1")
-
- assert hash(A) == hash(Object("A"))
-
- assert A != None
-
- raises(ValueError, lambda: Object(""))
-
def test_morphisms():
A = Object("A")
B = Object("B")
Please sign in to comment.
Something went wrong with that request. Please try again.