[PATCH] context: use common __repr__() implementation for all classes

Greg Ward greg-hg at gerg.ca
Tue Jul 21 13:29:40 CDT 2009


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1248200963 14400
# Node ID 4a01bd7064a1a7a3e8e33631f0ab9aec745775db
# Parent  0de7cf8db5fdde298d314225432a07e32bb16dfb
context: use common __repr__() implementation for all classes.

Before this, subclasses used their parent's __repr__(), which had
hardcoded class names.  That made repr() of a workingctx object
indistinguishable from repr() of a changectx.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -12,6 +12,10 @@
 
 propertycache = util.propertycache
 
+# common implementation of __repr__()
+def __repr__(self):
+    return "<%s %s>" % (self.__class__.__name__, str(self))
+
 class changectx(object):
     """A changecontext object makes access to data related to a particular
     changeset convenient."""
@@ -30,12 +34,11 @@
     def __str__(self):
         return short(self.node())
 
+    __repr__ = __repr__
+
     def __int__(self):
         return self.rev()
 
-    def __repr__(self):
-        return "<changectx %s>" % str(self)
-
     def __hash__(self):
         try:
             return hash(self._rev)
@@ -254,8 +257,7 @@
     def __str__(self):
         return "%s@%s" % (self.path(), short(self.node()))
 
-    def __repr__(self):
-        return "<filectx %s>" % str(self)
+    __repr__ = __repr__
 
     def __hash__(self):
         try:
@@ -754,6 +756,8 @@
     def __str__(self):
         return str(self._parents[0]) + "+"
 
+    __repr__ = __repr__
+
     def __int__(self):
         return self._rev
 
@@ -810,6 +814,7 @@
 
     def __nonzero__(self): return True
     def __str__(self): return "%s@%s" % (self.path(), self._changectx)
+    __repr__ = __repr__
     def path(self): return self._path
     def data(self): return self._data
     def flags(self): return self._flags


More information about the Mercurial-devel mailing list