Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
support renaming of Functor (define _repr_(), not __repr__())
Browse files Browse the repository at this point in the history
  • Loading branch information
pjbruin committed Apr 14, 2014
1 parent 37c8a8c commit 6bc7e6c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/sage/categories/action.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ cdef class Action(Functor):
def is_left(self):
return self._is_left

def __repr__(self):
def _repr_(self):
side = "Left" if self._is_left else "Right"
return "%s %s by %r on %r"%(side, self._repr_name_(), self.G,
self.underlying_set())
Expand Down Expand Up @@ -339,7 +339,7 @@ cdef class PrecomposedAction(Action):
def __invert__(self):
return PrecomposedAction(~self._action, self.left_precomposition, self.right_precomposition)

def __repr__(self):
def _repr_(self):
s = repr(self._action)
if self.left_precomposition is not None:
s += "\nwith precomposition on left by %s" % self.left_precomposition._default_repr_()
Expand Down
14 changes: 11 additions & 3 deletions src/sage/categories/functor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,22 @@ cdef class Functor(SageObject):
raise TypeError, "x (=%s) is not in %s"%(x, self.__domain)
return x

def __repr__(self):
def _repr_(self):
"""
TESTS::
sage: from sage.categories.functor import Functor
sage: F = Functor(Rings(),Fields())
sage: F #indirect doctest
Functor from Category of rings to Category of fields
A functor can be renamed if its type is a Python class
(see :trac:`16156)::
sage: I = IdentityFunctor(Rings()); I
The identity functor on Category of rings
sage: I.rename('Id'); I
Id
"""
return "Functor from %s to %s"%(self.__domain, self.__codomain)

Expand Down Expand Up @@ -453,7 +461,7 @@ class ForgetfulFunctor_generic(Functor):
"""
return ForgetfulFunctor, (self.domain(), self.codomain())

def __repr__(self):
def _repr_(self):
"""
TESTS::
Expand Down Expand Up @@ -557,7 +565,7 @@ class IdentityFunctor_generic(ForgetfulFunctor_generic):
"""
return IdentityFunctor, (self.domain(), )

def __repr__(self):
def _repr_(self):
"""
TESTS::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/morphism.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ cdef class Morphism(Map):
gens = domain.gens()
definition = tuple([self(x) for x in gens])
except (AttributeError, NotImplementedError):
definition = self.__repr__()
definition = repr(self)
return hash((domain, codomain, definition))

def __richcmp__(left, right, int op):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/pushout.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __str__(self):
import re
return re.sub("<.*'.*\.([^.]*)'>", "\\1", s)

def __repr__(self):
def _repr_(self):
"""
NOTE:
Expand Down Expand Up @@ -2926,7 +2926,7 @@ def __init__(self, gens, domain):
self._gens = gens
self._domain = domain

def __repr__(self):
def _repr_(self):
"""
EXAMPLES::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/weyl_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def quantum_bruhat_graph(self, index_set = ()):
from sage.graphs.digraph import DiGraph
WP = [x for x in self if x==x.coset_representative(index_set)]
return DiGraph([[x,i[0],i[1]] for x in WP for i in x.quantum_bruhat_successors(index_set, roots = True)],
name="Parabolic Quantum Bruhat Graph of %s for nodes %s"%(self.__repr__(),index_set))
name="Parabolic Quantum Bruhat Graph of %s for nodes %s"%(self, index_set))

class ElementMethods:

Expand Down

0 comments on commit 6bc7e6c

Please sign in to comment.