Patchwork [2,of,2] py3: use iter() instead of iterkeys()

login
register
mail settings
Submitter Rishabh Madan
Date March 15, 2017, 9:35 a.m.
Message ID <c289886e8c1fd3df6b72.1489570511@bunty>
Download mbox | patch
Permalink /patch/19360/
State Accepted
Headers show

Comments

Rishabh Madan - March 15, 2017, 9:35 a.m.
# HG changeset patch
# User Rishabh Madan <rishabhmadan96@gmail.com>
# Date 1489569941 -19800
#      Wed Mar 15 14:55:41 2017 +0530
# Node ID c289886e8c1fd3df6b72f7019e930494ecc4c3b0
# Parent  1ada79790380d3f9e416780f6447b383cc18f817
py3: use iter() instead of iterkeys()

The iterkeys() method has been deprecated for python3. This patch uses iter()
over dict.keys() to get the iterator object.
Pulkit Goyal - March 15, 2017, 9:44 a.m.
The series LGTM as I also have the same patches locally.

On Wed, Mar 15, 2017 at 3:05 PM, Rishabh Madan <rishabhmadan96@gmail.com>
wrote:

> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96@gmail.com>
> # Date 1489569941 -19800
> #      Wed Mar 15 14:55:41 2017 +0530
> # Node ID c289886e8c1fd3df6b72f7019e930494ecc4c3b0
> # Parent  1ada79790380d3f9e416780f6447b383cc18f817
> py3: use iter() instead of iterkeys()
>
> The iterkeys() method has been deprecated for python3. This patch uses
> iter()
> over dict.keys() to get the iterator object.
>
> diff -r 1ada79790380 -r c289886e8c1f mercurial/util.py
> --- a/mercurial/util.py Wed Mar 15 14:51:18 2017 +0530
> +++ b/mercurial/util.py Wed Mar 15 14:55:41 2017 +0530
> @@ -2918,7 +2918,10 @@
>              del dirs[base]
>
>      def __iter__(self):
> -        return self._dirs.iterkeys()
> +        if pycompat.ispy3:
> +            return iter(self._dirs.keys())
> +        else:
> +            return self._dirs.iterkeys()
>
>      def __contains__(self, d):
>          return d in self._dirs
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Yuya Nishihara - March 15, 2017, 1:06 p.m.
On Wed, 15 Mar 2017 15:05:11 +0530, Rishabh Madan wrote:
> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96@gmail.com>
> # Date 1489569941 -19800
> #      Wed Mar 15 14:55:41 2017 +0530
> # Node ID c289886e8c1fd3df6b72f7019e930494ecc4c3b0
> # Parent  1ada79790380d3f9e416780f6447b383cc18f817
> py3: use iter() instead of iterkeys()
> 
> The iterkeys() method has been deprecated for python3. This patch uses iter()
> over dict.keys() to get the iterator object.
> 
> diff -r 1ada79790380 -r c289886e8c1f mercurial/util.py
> --- a/mercurial/util.py	Wed Mar 15 14:51:18 2017 +0530
> +++ b/mercurial/util.py	Wed Mar 15 14:55:41 2017 +0530
> @@ -2918,7 +2918,10 @@
>              del dirs[base]
>  
>      def __iter__(self):
> -        return self._dirs.iterkeys()
> +        if pycompat.ispy3:
> +            return iter(self._dirs.keys())
> +        else:
> +            return self._dirs.iterkeys()

Can't we simply do return iter(self._dirs) ?

Patch

diff -r 1ada79790380 -r c289886e8c1f mercurial/util.py
--- a/mercurial/util.py	Wed Mar 15 14:51:18 2017 +0530
+++ b/mercurial/util.py	Wed Mar 15 14:55:41 2017 +0530
@@ -2918,7 +2918,10 @@ 
             del dirs[base]
 
     def __iter__(self):
-        return self._dirs.iterkeys()
+        if pycompat.ispy3:
+            return iter(self._dirs.keys())
+        else:
+            return self._dirs.iterkeys()
 
     def __contains__(self, d):
         return d in self._dirs