D5010: py3: encode str to bytes

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Fri Oct 12 17:02:35 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG56ea22fa55f0: py3: encode str to bytes (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5010?vs=11923&id=11955

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

AFFECTED FILES
  mercurial/lsprof.py

CHANGE DETAILS

diff --git a/mercurial/lsprof.py b/mercurial/lsprof.py
--- a/mercurial/lsprof.py
+++ b/mercurial/lsprof.py
@@ -91,6 +91,8 @@
 
 def label(code):
     if isinstance(code, str):
+        if sys.version_info.major >= 3:
+            code = code.encode('latin-1')
         return code
     try:
         mname = _fn2mod[code.co_filename]
@@ -104,10 +106,14 @@
                 mname = _fn2mod[code.co_filename] = k
                 break
         else:
-            mname = _fn2mod[code.co_filename] = '<%s>' % code.co_filename
+            mname = _fn2mod[code.co_filename] = r'<%s>' % code.co_filename
+
+    res = r'%s:%d(%s)' % (mname, code.co_firstlineno, code.co_name)
 
-    return '%s:%d(%s)' % (mname, code.co_firstlineno, code.co_name)
+    if sys.version_info.major >= 3:
+        res = res.encode('latin-1')
 
+    return res
 
 if __name__ == '__main__':
     import os



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


More information about the Mercurial-devel mailing list