Patchwork [1,of,4,py3] maplist: replace instances of map() with pycompat.maplist() [1 of 4]

login
register
mail settings
Submitter Pulkit Goyal
Date March 24, 2017, 3:18 p.m.
Message ID <35e6f3d8dbb1242c6cac.1490368681@pulkit-goyal>
Download mbox | patch
Permalink /patch/19641/
State Rejected
Headers show

Comments

Pulkit Goyal - March 24, 2017, 3:18 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1490367921 -19800
#      Fri Mar 24 20:35:21 2017 +0530
# Node ID 35e6f3d8dbb1242c6cac1c64fd799db543e30444
# Parent  e8bd005c0af791a87903de339482692db1137ff0
maplist: replace instances of map() with pycompat.maplist() [1 of 4]

This series replaces the instances of the inbuilt map() function with
pycompat.maplist() as map() returns a map object instead of list on Python 3.
Pulkit Goyal - March 24, 2017, 3:30 p.m.
This series is a part of fixing things which we already know will lead to
exception or wrong result. So instead of waiting for those exceptions to
pop up, it fixes them. It fixes all the occurrences in mercurial/ (couple
of occurrences are left where using maplist was not required).

On Fri, Mar 24, 2017 at 8:48 PM, Pulkit Goyal <7895pulkit@gmail.com> wrote:

> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1490367921 -19800
> #      Fri Mar 24 20:35:21 2017 +0530
> # Node ID 35e6f3d8dbb1242c6cac1c64fd799db543e30444
> # Parent  e8bd005c0af791a87903de339482692db1137ff0
> maplist: replace instances of map() with pycompat.maplist() [1 of 4]
>
> This series replaces the instances of the inbuilt map() function with
> pycompat.maplist() as map() returns a map object instead of list on Python
> 3.
>
> diff -r e8bd005c0af7 -r 35e6f3d8dbb1 mercurial/byterange.py
> --- a/mercurial/byterange.py    Thu Mar 23 12:03:19 2017 -0700
> +++ b/mercurial/byterange.py    Fri Mar 24 20:35:21 2017 +0530
> @@ -28,6 +28,7 @@
>  import stat
>
>  from . import (
> +    pycompat,
>      util,
>  )
>
> @@ -278,7 +279,7 @@
>              raise urlerr.urlerror(msg)
>          path, attrs = splitattr(req.get_selector())
>          dirs = path.split('/')
> -        dirs = map(unquote, dirs)
> +        dirs = pycompat.maplist(unquote, dirs)
>          dirs, file = dirs[:-1], dirs[-1]
>          if dirs and not dirs[0]:
>              dirs = dirs[1:]
> diff -r e8bd005c0af7 -r 35e6f3d8dbb1 mercurial/chgserver.py
> --- a/mercurial/chgserver.py    Thu Mar 23 12:03:19 2017 -0700
> +++ b/mercurial/chgserver.py    Fri Mar 24 20:35:21 2017 +0530
> @@ -151,7 +151,7 @@
>          except OSError:
>              # could be ENOENT, EPERM etc. not fatal in any case
>              pass
> -    return _hashlist(map(trystat, paths))[:12]
> +    return _hashlist(pycompat.maplist(trystat, paths))[:12]
>
>  class hashstate(object):
>      """a structure storing confighash, mtimehash, paths used for
> mtimehash"""
> diff -r e8bd005c0af7 -r 35e6f3d8dbb1 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py      Thu Mar 23 12:03:19 2017 -0700
> +++ b/mercurial/cmdutil.py      Fri Mar 24 20:35:21 2017 +0530
> @@ -1573,12 +1573,13 @@
>      fm.write('precnode', '%s ', hex(marker.precnode()))
>      succs = marker.succnodes()
>      fm.condwrite(succs, 'succnodes', '%s ',
> -                 fm.formatlist(map(hex, succs), name='node'))
> +                 fm.formatlist(pycompat.maplist(hex, succs),
> name='node'))
>      fm.write('flag', '%X ', marker.flags())
>      parents = marker.parentnodes()
>      if parents is not None:
>          fm.write('parentnodes', '{%s} ',
> -                 fm.formatlist(map(hex, parents), name='node', sep=', '))
> +                 fm.formatlist(pycompat.maplist(hex, parents),
> +                 name='node', sep=', '))
>      fm.write('date', '(%s) ', fm.formatdate(marker.date()))
>      meta = marker.metadata().copy()
>      meta.pop('date', None)
> diff -r e8bd005c0af7 -r 35e6f3d8dbb1 mercurial/commands.py
> --- a/mercurial/commands.py     Thu Mar 23 12:03:19 2017 -0700
> +++ b/mercurial/commands.py     Fri Mar 24 20:35:21 2017 +0530
> @@ -1349,7 +1349,7 @@
>              raise error.Abort(_("--base is incompatible with specifying "
>                                 "a destination"))
>          common = [repo.lookup(rev) for rev in base]
> -        heads = revs and map(repo.lookup, revs) or None
> +        heads = revs and pycompat.maplist(repo.lookup, revs) or None
>          outgoing = discovery.outgoing(repo, common, heads)
>          cg = changegroup.getchangegroup(repo, 'bundle', outgoing,
>                                          bundlecaps=bundlecaps,
> @@ -1360,7 +1360,7 @@
>          dest, branches = hg.parseurl(dest, opts.get('branch'))
>          other = hg.peer(repo, opts, dest)
>          revs, checkout = hg.addbranchrevs(repo, repo, branches, revs)
> -        heads = revs and map(repo.lookup, revs) or revs
> +        heads = revs and pycompat.maplist(repo.lookup, revs) or revs
>          outgoing = discovery.findcommonoutgoing(repo, other,
>                                                  onlyheads=heads,
>                                                  force=opts.get('force'),
>
Yuya Nishihara - March 24, 2017, 3:49 p.m.
On Fri, 24 Mar 2017 21:00:24 +0530, Pulkit Goyal wrote:
> This series is a part of fixing things which we already know will lead to
> exception or wrong result. So instead of waiting for those exceptions to
> pop up, it fixes them. It fixes all the occurrences in mercurial/ (couple
> of occurrences are left where using maplist was not required).

Not all map() are needed to be converted to maplist(). If we don't want to
sort out them, we can simply redirect map to maplist by importer.
Augie Fackler - March 24, 2017, 6:07 p.m.
On Sat, Mar 25, 2017 at 12:49:05AM +0900, Yuya Nishihara wrote:
> On Fri, 24 Mar 2017 21:00:24 +0530, Pulkit Goyal wrote:
> > This series is a part of fixing things which we already know will lead to
> > exception or wrong result. So instead of waiting for those exceptions to
> > pop up, it fixes them. It fixes all the occurrences in mercurial/ (couple
> > of occurrences are left where using maplist was not required).
>
> Not all map() are needed to be converted to maplist(). If we don't want to
> sort out them, we can simply redirect map to maplist by importer.

Yeah, I'd rather we trip over cases where we used map
not-as-an-iterator and fix them incrementally rather than just
touching them all wholesale.

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff -r e8bd005c0af7 -r 35e6f3d8dbb1 mercurial/byterange.py
--- a/mercurial/byterange.py	Thu Mar 23 12:03:19 2017 -0700
+++ b/mercurial/byterange.py	Fri Mar 24 20:35:21 2017 +0530
@@ -28,6 +28,7 @@ 
 import stat
 
 from . import (
+    pycompat,
     util,
 )
 
@@ -278,7 +279,7 @@ 
             raise urlerr.urlerror(msg)
         path, attrs = splitattr(req.get_selector())
         dirs = path.split('/')
-        dirs = map(unquote, dirs)
+        dirs = pycompat.maplist(unquote, dirs)
         dirs, file = dirs[:-1], dirs[-1]
         if dirs and not dirs[0]:
             dirs = dirs[1:]
diff -r e8bd005c0af7 -r 35e6f3d8dbb1 mercurial/chgserver.py
--- a/mercurial/chgserver.py	Thu Mar 23 12:03:19 2017 -0700
+++ b/mercurial/chgserver.py	Fri Mar 24 20:35:21 2017 +0530
@@ -151,7 +151,7 @@ 
         except OSError:
             # could be ENOENT, EPERM etc. not fatal in any case
             pass
-    return _hashlist(map(trystat, paths))[:12]
+    return _hashlist(pycompat.maplist(trystat, paths))[:12]
 
 class hashstate(object):
     """a structure storing confighash, mtimehash, paths used for mtimehash"""
diff -r e8bd005c0af7 -r 35e6f3d8dbb1 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Thu Mar 23 12:03:19 2017 -0700
+++ b/mercurial/cmdutil.py	Fri Mar 24 20:35:21 2017 +0530
@@ -1573,12 +1573,13 @@ 
     fm.write('precnode', '%s ', hex(marker.precnode()))
     succs = marker.succnodes()
     fm.condwrite(succs, 'succnodes', '%s ',
-                 fm.formatlist(map(hex, succs), name='node'))
+                 fm.formatlist(pycompat.maplist(hex, succs), name='node'))
     fm.write('flag', '%X ', marker.flags())
     parents = marker.parentnodes()
     if parents is not None:
         fm.write('parentnodes', '{%s} ',
-                 fm.formatlist(map(hex, parents), name='node', sep=', '))
+                 fm.formatlist(pycompat.maplist(hex, parents),
+                 name='node', sep=', '))
     fm.write('date', '(%s) ', fm.formatdate(marker.date()))
     meta = marker.metadata().copy()
     meta.pop('date', None)
diff -r e8bd005c0af7 -r 35e6f3d8dbb1 mercurial/commands.py
--- a/mercurial/commands.py	Thu Mar 23 12:03:19 2017 -0700
+++ b/mercurial/commands.py	Fri Mar 24 20:35:21 2017 +0530
@@ -1349,7 +1349,7 @@ 
             raise error.Abort(_("--base is incompatible with specifying "
                                "a destination"))
         common = [repo.lookup(rev) for rev in base]
-        heads = revs and map(repo.lookup, revs) or None
+        heads = revs and pycompat.maplist(repo.lookup, revs) or None
         outgoing = discovery.outgoing(repo, common, heads)
         cg = changegroup.getchangegroup(repo, 'bundle', outgoing,
                                         bundlecaps=bundlecaps,
@@ -1360,7 +1360,7 @@ 
         dest, branches = hg.parseurl(dest, opts.get('branch'))
         other = hg.peer(repo, opts, dest)
         revs, checkout = hg.addbranchrevs(repo, repo, branches, revs)
-        heads = revs and map(repo.lookup, revs) or revs
+        heads = revs and pycompat.maplist(repo.lookup, revs) or revs
         outgoing = discovery.findcommonoutgoing(repo, other,
                                                 onlyheads=heads,
                                                 force=opts.get('force'),