[PATCH py3 V2] revlog: explicitly evaluate list to return

Yuya Nishihara yuya at tcha.org
Fri Mar 17 08:36:22 EDT 2017


On Thu, 16 Mar 2017 15:34:11 -0700, Gregory Szorc wrote:
> On Thu, Mar 16, 2017 at 2:51 PM, Pulkit Goyal <7895pulkit at gmail.com> wrote:
> 
> > # HG changeset patch
> > # User Pulkit Goyal <7895pulkit at gmail.com>
> > # Date 1489639281 -19800
> > #      Thu Mar 16 10:11:21 2017 +0530
> > # Node ID 16e1d9557dcebfe827060a4d31781cb7498c2c45
> > # Parent  e082ef765e4112ef69d3345369b142c87f1da3f4
> > revlog: explicitly evaluate list to return
> >
> > On python 3, map returns an iterator so we need to convert it to list
> > before
> > finding the len or subscripting it.
> >
> > After this `hg status --all` works on Python 3.
> >
> > diff -r e082ef765e41 -r 16e1d9557dce mercurial/revlog.py
> > --- a/mercurial/revlog.py       Thu Mar 16 10:01:12 2017 +0530
> > +++ b/mercurial/revlog.py       Thu Mar 16 10:11:21 2017 +0530
> > @@ -943,7 +943,7 @@
> >              ancs = self.index.commonancestorsheads(a, b)
> >          except (AttributeError, OverflowError): # C implementation failed
> >              ancs = ancestor.commonancestorsheads(self.parentrevs, a, b)
> > -        return map(self.node, ancs)
> > +        return list(map(self.node, ancs))
> >
> >
> This will create a list copy in Python 2, which could have performance
> implications. But for this function, the list shouldn't have many elements,
> so it is probably OK. Something to watch out for when doing other porting
> work. It /might/ be worthwhile to have a pycompat.maplist() wrapper or some
> such.

+1 for pycompat function. It's also useful for grepping py3 workarounds.


More information about the Mercurial-devel mailing list