Patchwork tests: avoid implicit conversion of str to unicode

login
register
mail settings
Submitter Manuel Jacob
Date March 6, 2020, 9:35 a.m.
Message ID <14e2295705434054ed9c.1583487305@tmp>
Download mbox | patch
Permalink /patch/45535/
State Superseded
Headers show

Comments

Manuel Jacob - March 6, 2020, 9:35 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1583428219 -3600
#      Thu Mar 05 18:10:19 2020 +0100
# Node ID 14e2295705434054ed9c697143bb7207ebd1777d
# Parent  4cabeea6d21456ae4d560ef72adffe11d77d5387
# EXP-Topic remove-implicit-str-conversions
tests: avoid implicit conversion of str to unicode

On Python 2, str.encode('ascii') implicitly converts the string to unicode and
then back to str.

Since the point of this expression is to convert a bool to a str, the '%r'
conversion specifier can be used instead in the format string.
Yuya Nishihara - March 6, 2020, 2:46 p.m.
On Fri, 06 Mar 2020 10:35:05 +0100, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1583428219 -3600
> #      Thu Mar 05 18:10:19 2020 +0100
> # Node ID 14e2295705434054ed9c697143bb7207ebd1777d
> # Parent  4cabeea6d21456ae4d560ef72adffe11d77d5387
> # EXP-Topic remove-implicit-str-conversions
> tests: avoid implicit conversion of str to unicode

Queued, thanks.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1428,7 +1428,7 @@ 
             )
             hgrc.write(b'[web]\n')
             hgrc.write(b'address = localhost\n')
-            hgrc.write(b'ipv6 = %s\n' % str(self._useipv6).encode('ascii'))
+            hgrc.write(b'ipv6 = %r\n' % self._useipv6)
             hgrc.write(b'server-header = testing stub value\n')
 
             for opt in self._extraconfigopts: