Patchwork encoding: use i.startswith() instead of i[0] to eliminate py2/3 divergence

login
register
mail settings
Submitter Yuya Nishihara
Date May 16, 2017, 3:16 p.m.
Message ID <13f44d66157096e3bf9c.1494947797@mimosa>
Download mbox | patch
Permalink /patch/20639/
State Accepted
Headers show

Comments

Yuya Nishihara - May 16, 2017, 3:16 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1494945398 -32400
#      Tue May 16 23:36:38 2017 +0900
# Node ID 13f44d66157096e3bf9c7f30bd4df802c38b971e
# Parent  288f218a3641333bd64aac807d0b81205049c047
encoding: use i.startswith() instead of i[0] to eliminate py2/3 divergence
Augie Fackler - May 16, 2017, 6:28 p.m.
On Wed, May 17, 2017 at 12:16:37AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1494945398 -32400
> #      Tue May 16 23:36:38 2017 +0900
> # Node ID 13f44d66157096e3bf9c7f30bd4df802c38b971e
> # Parent  288f218a3641333bd64aac807d0b81205049c047
> encoding: use i.startswith() instead of i[0] to eliminate py2/3 divergence

queued, thanks

Patch

diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -29,10 +29,7 @@  if pycompat.ispy3:
            "200c 200d 200e 200f 202a 202b 202c 202d 202e "
            "206a 206b 206c 206d 206e 206f feff".split()]
 # verify the next function will work
-if pycompat.ispy3:
-    assert set(i[0] for i in _ignore) == {ord(b'\xe2'), ord(b'\xef')}
-else:
-    assert set(i[0] for i in _ignore) == {"\xe2", "\xef"}
+assert all(i.startswith(("\xe2", "\xef")) for i in _ignore)
 
 def hfsignoreclean(s):
     """Remove codepoints ignored by HFS+ from s.