Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 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 | bf728e72a219 |
children | 1df98fc923d4 |
comparison
equal
deleted
inserted
replaced
32612:a8262b7784f9 | 32613:e7eb7494e98d |
---|---|
75 | 75 |
76 def __int__(self): | 76 def __int__(self): |
77 return self.rev() | 77 return self.rev() |
78 | 78 |
79 def __repr__(self): | 79 def __repr__(self): |
80 return "<%s %s>" % (type(self).__name__, str(self)) | 80 return r"<%s %s>" % (type(self).__name__, str(self)) |
81 | 81 |
82 def __eq__(self, other): | 82 def __eq__(self, other): |
83 try: | 83 try: |
84 return type(self) == type(other) and self._rev == other._rev | 84 return type(self) == type(other) and self._rev == other._rev |
85 except AttributeError: | 85 except AttributeError: |
1401 self._extra['branch'] = branch | 1401 self._extra['branch'] = branch |
1402 if self._extra['branch'] == '': | 1402 if self._extra['branch'] == '': |
1403 self._extra['branch'] = 'default' | 1403 self._extra['branch'] = 'default' |
1404 | 1404 |
1405 def __str__(self): | 1405 def __str__(self): |
1406 return str(self._parents[0]) + "+" | 1406 return str(self._parents[0]) + r"+" |
1407 | 1407 |
1408 def __nonzero__(self): | 1408 def __nonzero__(self): |
1409 return True | 1409 return True |
1410 | 1410 |
1411 __bool__ = __nonzero__ | 1411 __bool__ = __nonzero__ |