Patchwork [py3,resend] dirstate: use iter.__next__ instead of iter.next

login
register
mail settings
Submitter Pulkit Goyal
Date March 19, 2017, 8:54 a.m.
Message ID <f2efba4759b00ea56f11.1489913648@pulkit-goyal>
Download mbox | patch
Permalink /patch/19448/
State Not Applicable
Headers show

Comments

Pulkit Goyal - March 19, 2017, 8:54 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1489720184 -19800
#      Fri Mar 17 08:39:44 2017 +0530
# Node ID f2efba4759b00ea56f11f667e208253685e8ea59
# Parent  a5bad127128d8f60060be53d161acfa7a32a17d5
dirstate: use iter.__next__ instead of iter.next

In Python 3 world, iter.next() is renamed to iter.__next__()
Yuya Nishihara - March 19, 2017, 2:16 p.m.
On Sun, 19 Mar 2017 14:24:08 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1489720184 -19800
> #      Fri Mar 17 08:39:44 2017 +0530
> # Node ID f2efba4759b00ea56f11f667e208253685e8ea59
> # Parent  a5bad127128d8f60060be53d161acfa7a32a17d5
> dirstate: use iter.__next__ instead of iter.next
> 
> In Python 3 world, iter.next() is renamed to iter.__next__()
> 
> diff -r a5bad127128d -r f2efba4759b0 mercurial/dirstate.py
> --- a/mercurial/dirstate.py	Wed Mar 15 15:48:57 2017 -0700
> +++ b/mercurial/dirstate.py	Fri Mar 17 08:39:44 2017 +0530
> @@ -1115,7 +1115,10 @@
>              else:
>                  # We may not have walked the full directory tree above,
>                  # so stat and check everything we missed.
> -                nf = iter(visit).next
> +                if pycompat.ispy3:
> +                    nf = iter(visit).__next__
> +                else:
> +                    nf = iter(visit).next

Do you have some perf numbers of it.__next__ vs next(it) ? If the overhead
isn't significant, we can use next().

Patch

diff -r a5bad127128d -r f2efba4759b0 mercurial/dirstate.py
--- a/mercurial/dirstate.py	Wed Mar 15 15:48:57 2017 -0700
+++ b/mercurial/dirstate.py	Fri Mar 17 08:39:44 2017 +0530
@@ -1115,7 +1115,10 @@ 
             else:
                 # We may not have walked the full directory tree above,
                 # so stat and check everything we missed.
-                nf = iter(visit).next
+                if pycompat.ispy3:
+                    nf = iter(visit).__next__
+                else:
+                    nf = iter(visit).next
                 for st in util.statfiles([join(i) for i in visit]):
                     results[nf()] = st
         return results