Patchwork D2042: py3: add __bytes__() for mq.patchheader and make sure __str__ returns str

login
register
mail settings
Submitter phabricator
Date Feb. 5, 2018, 8:23 a.m.
Message ID <differential-rev-PHID-DREV-eagay5a556rmrzcgr7lf-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27302/
State Superseded
Headers show

Comments

phabricator - Feb. 5, 2018, 8:23 a.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Before this patch, __str__() function for mq.patchheader class return bytes
  which is not str on Python 3. So let's move that logic to __bytes__() and for
  __str__() convert the return value of __bytes__() to str.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2042

AFFECTED FILES
  hgext/mq.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -396,12 +396,14 @@ 
                 self.comments.append('')
             self.comments.append(message)
 
-    def __str__(self):
+    def __bytes__(self):
         s = '\n'.join(self.comments).rstrip()
         if not s:
             return ''
         return s + '\n\n'
 
+    __str__ = encoding.strmethod(__bytes__)
+
     def _delmsg(self):
         '''Remove existing message, keeping the rest of the comments fields.
         If comments contains 'subject: ', message will prepend