Patchwork [1,of,7] py3: pass range() into list() to get one explicitly

login
register
mail settings
Submitter Pulkit Goyal
Date June 17, 2017, 12:45 p.m.
Message ID <9fc0c5a06ad8573d46b1.1497703519@workspace>
Download mbox | patch
Permalink /patch/21454/
State Accepted
Headers show

Comments

Pulkit Goyal - June 17, 2017, 12:45 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1497690482 -19800
#      Sat Jun 17 14:38:02 2017 +0530
# Node ID 9fc0c5a06ad8573d46b10212e856cd14cfef0e16
# Parent  9d472b219fb07e011c7a6255c5be47e6fc66229c
py3: pass range() into list() to get one explicitly

range() on python 3 returns a generator whereas on python 2 returns a list. So
to get a list on python 3, we passed it into list()
Yuya Nishihara - June 18, 2017, 6:23 a.m.
On Sat, 17 Jun 2017 18:15:19 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1497690482 -19800
> #      Sat Jun 17 14:38:02 2017 +0530
> # Node ID 9fc0c5a06ad8573d46b10212e856cd14cfef0e16
> # Parent  9d472b219fb07e011c7a6255c5be47e6fc66229c
> py3: pass range() into list() to get one explicitly

Queued 1-4, 6, and 7, thanks.

Patch

diff --git a/tests/test-ancestor.py b/tests/test-ancestor.py
--- a/tests/test-ancestor.py
+++ b/tests/test-ancestor.py
@@ -42,7 +42,7 @@ 
                 p1 = i - 1
             else:
                 p1 = rng.randrange(i - 1)
-            p2 = rng.choice(range(0, p1) + range(p1 + 1, i))
+            p2 = rng.choice(list(range(0, p1)) + list(range(p1 + 1, i)))
             graph[i] = [p1, p2]
         elif rng.random() < prevprob:
             graph[i] = [i - 1]