Patchwork [1,of,2,hglib] util: don't try to use itertools.izip under Python 3 (issue4520)

login
register
mail settings
Submitter Brett Cannon
Date March 20, 2015, 8:35 p.m.
Message ID <0808bb03add5fe4f264a.1426883701@bcannon-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/8204/
State Accepted
Headers show

Comments

Brett Cannon - March 20, 2015, 8:35 p.m.
# HG changeset patch
# User Brett Cannon <brett@python.org>
# Date 1426883573 14400
#      Fri Mar 20 16:32:53 2015 -0400
# Node ID 0808bb03add5fe4f264ac90926f64b3ca6b75730
# Parent  b91356bf7186845d21a219fa5282f1fa9dade69c
util: don't try to use itertools.izip under Python 3 (issue4520)

In Python 3, itertools.izip became builtins.zip.

Patch

diff -r b91356bf7186 -r 0808bb03add5 hglib/util.py
--- a/hglib/util.py	Thu Mar 19 17:42:46 2015 -0400
+++ b/hglib/util.py	Fri Mar 20 16:32:53 2015 -0400
@@ -1,4 +1,4 @@ 
-import itertools, os, subprocess, sys
+import os, subprocess, sys
 from hglib import error
 try:
     from io import BytesIO
@@ -6,10 +6,14 @@ 
     from cStringIO import StringIO as BytesIO
 
 if sys.version_info[0] > 2:
+    izip = zip
+
     def b(s):
         """Encode the string as bytes."""
         return s.encode('latin-1')
 else:
+    from itertools import izip
+
     def b(s):
         """Encode the string as bytes."""
         return s
@@ -21,7 +25,7 @@ 
 def grouper(n, iterable):
     ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] '''
     args = [iter(iterable)] * n
-    return itertools.izip(*args)
+    return izip(*args)
 
 def eatlines(s, n):
     """