Patchwork [05,of,10] py3: ensure that we don't concat bytes and str and the end result is bytes

login
register
mail settings
Submitter Pulkit Goyal
Date May 31, 2017, 9:47 p.m.
Message ID <8a1b753a1eac83bd2b07.1496267221@workspace>
Download mbox | patch
Permalink /patch/21100/
State Accepted
Headers show

Comments

Pulkit Goyal - May 31, 2017, 9:47 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1496261494 -19800
#      Thu Jun 01 01:41:34 2017 +0530
# Node ID 8a1b753a1eac83bd2b07ad1b3aa454e383794329
# Parent  66f3c6ec7827f4bc1d28673c0478ca42d60656ed
py3: ensure that we don't concat bytes and str and the end result is bytes

Here obj.__module__ and obj.__name__ are str. Either we can convert them to
bytes or use an r'' and convert back to bytes when concat is done. I preferred
the later one since we are encoding only once here.

Patch

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -31,7 +31,7 @@ 
 
     if callable(funcname):
         obj = funcname
-        funcname = obj.__module__ + "." + obj.__name__
+        funcname = pycompat.sysbytes(obj.__module__ + r"." + obj.__name__)
     else:
         d = funcname.rfind('.')
         if d == -1: