Patchwork [4,of,9,py3,v2] context: implement both __bytes__ and __str__ for Python 3

login
register
mail settings
Submitter Augie Fackler
Date March 12, 2017, 5:38 p.m.
Message ID <3863a163a20c34a52ff5.1489340298@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/19182/
State Superseded
Headers show

Comments

Augie Fackler - March 12, 2017, 5:38 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1489283860 18000
#      Sat Mar 11 20:57:40 2017 -0500
# Node ID 3863a163a20c34a52ff5d391d4391b01bc029de1
# Parent  406938c2ae5042166b7a22cad39210cb08c80a37
context: implement both __bytes__ and __str__ for Python 3

They're very similar, for obvious reasons.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -65,6 +65,12 @@  class basectx(object):
         return o
 
     def __str__(self):
+        r = short(self.node())
+        if pycompat.ispy3:
+            return r.decode('ascii')
+        return r
+
+    def __bytes__(self):
         return short(self.node())
 
     def __int__(self):