Patchwork py3: change explicit conversion from str to bytes

login
register
mail settings
Submitter Rishabh Madan
Date March 17, 2017, 11:43 a.m.
Message ID <2aac5780c5b3c30602ca.1489751033@bunty>
Download mbox | patch
Permalink /patch/19418/
State Changes Requested
Headers show

Comments

Rishabh Madan - March 17, 2017, 11:43 a.m.
# HG changeset patch
# User Rishabh Madan <rishabhmadan96@gmail.com>
# Date 1489746142 -19800
#      Fri Mar 17 15:52:22 2017 +0530
# Node ID 2aac5780c5b3c30602ca128cfeb6e38a42f2c0fb
# Parent  a5bad127128d8f60060be53d161acfa7a32a17d5
py3: change explicit conversion from str to bytes
Yuya Nishihara - March 17, 2017, 12:30 p.m.
On Fri, 17 Mar 2017 17:13:53 +0530, Rishabh Madan wrote:
> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96@gmail.com>
> # Date 1489746142 -19800
> #      Fri Mar 17 15:52:22 2017 +0530
> # Node ID 2aac5780c5b3c30602ca128cfeb6e38a42f2c0fb
> # Parent  a5bad127128d8f60060be53d161acfa7a32a17d5
> py3: change explicit conversion from str to bytes
> 
> diff -r a5bad127128d -r 2aac5780c5b3 mercurial/commands.py
> --- a/mercurial/commands.py	Wed Mar 15 15:48:57 2017 -0700
> +++ b/mercurial/commands.py	Fri Mar 17 15:52:22 2017 +0530
> @@ -1813,7 +1813,7 @@
>      matched = False
>      for section, name, value in ui.walkconfig(untrusted=untrusted):
>          source = ui.configsource(section, name, untrusted)
> -        value = str(value)
> +        value = bytes(value)

On Python 3, bytes() can't be used to stringify arbitrary objects, e.g.

  >>> bytes(2)
  b'\x00\x00'

pycompat.bytestr() should be usable here.

Patch

diff -r a5bad127128d -r 2aac5780c5b3 mercurial/commands.py
--- a/mercurial/commands.py	Wed Mar 15 15:48:57 2017 -0700
+++ b/mercurial/commands.py	Fri Mar 17 15:52:22 2017 +0530
@@ -1813,7 +1813,7 @@ 
     matched = False
     for section, name, value in ui.walkconfig(untrusted=untrusted):
         source = ui.configsource(section, name, untrusted)
-        value = str(value)
+        value = bytes(value)
         if fm.isplain():
             source = source or 'none'
             value = value.replace('\n', '\\n')