changeset 32613:e7eb7494e98d

py3: make sure we return strings from __str__ and __repr__ On Python 3: >>> class abc: ... def __repr__(self): ... return b'abc' ... >>> abc() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __repr__ returned non-string (type bytes) >>> class abc: ... def __str__(self): ... return b'abc' ... >>> str(abc()) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __str__ returned non-string (type bytes) So the __str__ and __repr__ must return strings.
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 01 Jun 2017 00:00:10 +0530
parents a8262b7784f9
children 4b426ae96ff2
files mercurial/context.py
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Wed May 31 23:48:52 2017 +0530
+++ b/mercurial/context.py	Thu Jun 01 00:00:10 2017 +0530
@@ -77,7 +77,7 @@
         return self.rev()
 
     def __repr__(self):
-        return "<%s %s>" % (type(self).__name__, str(self))
+        return r"<%s %s>" % (type(self).__name__, str(self))
 
     def __eq__(self, other):
         try:
@@ -1403,7 +1403,7 @@
             self._extra['branch'] = 'default'
 
     def __str__(self):
-        return str(self._parents[0]) + "+"
+        return str(self._parents[0]) + r"+"
 
     def __nonzero__(self):
         return True