Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extend the string printer to print Object and Morphism.

Also add the corresponding tests.
  • Loading branch information...
commit 631cb3d347c886978116cf697e981b1c62e758dd 1 parent f888e7e
@scolobb authored
Showing with 26 additions and 0 deletions.
  1. +11 −0 sympy/printing/str.py
  2. +15 −0 sympy/printing/tests/test_str.py
View
11 sympy/printing/str.py
@@ -526,7 +526,18 @@ def _print_DMP(self, p):
def _print_DMF(self, expr):
return self._print_DMP(expr)
+ def _print_Object(self, object):
+ return 'Object("%s")' % object.name
+ def _print_Morphism(self, morphism):
+ if len(morphism.components) == 1:
+ return 'Morphism(%s, %s, "%s")' % \
+ (morphism.domain, morphism.codomain, morphism.name)
+ else:
+ names = ""
+ for component in morphism.components:
+ names += str(component) + ", "
+ return "[%s]" % names[:-2]
def sstr(expr, **settings):
"""Returns the expression as a string.
View
15 sympy/printing/tests/test_str.py
@@ -471,3 +471,18 @@ def test_PrettyPoly():
R = QQ[x, y]
assert sstr(F.convert(x/(x + y))) == sstr(x/(x + y))
assert sstr(R.convert(x + y)) == sstr(x + y)
+
+def test_categories():
+ from sympy.categories import Object, Morphism
+
+ A = Object("A")
+ B = Object("B")
+ C = Object("C")
+
+ f = Morphism(A, B, "f")
+ g = Morphism(B, C, "g")
+
+ assert str(A) == 'Object("A")'
+ assert str(f) == 'Morphism(Object("A"), Object("B"), "f")'
+ assert str(g * f) == '[Morphism(Object("A"), Object("B"), "f"), \
+Morphism(Object("B"), Object("C"), "g")]'
Please sign in to comment.
Something went wrong with that request. Please try again.