[PATCH 4 of 9] record extension: removed 'reduce' calls, as they are unsupported by py3k

Dan Villiom Podlaski Christiansen danchr at gmail.com
Fri Jul 2 15:55:05 CDT 2010


On 2 Jul 2010, at 00:27, Renato Cunha wrote:

> hgext/record.py |  4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
> 
> 
> # HG changeset patch
> # User Renato Cunha <renatoc at gmail.com>
> # Date 1278023223 10800
> # Node ID 4085a4d5de97332e368254776bb671c02cf757bb
> # Parent  78781c121e747757b06fdab7ed0b5f190e4972d3
> record extension: removed 'reduce' calls, as they are unsupported by py3k.
> 
> Quoting python's documentation, "Note that sum(range(n), m) is equivalent to
> reduce(operator.add, range(n), m)". The "sum" function is a builtin from 2.3
> on and there's no reason for not to use it.
> 
> diff --git a/hgext/record.py b/hgext/record.py
> --- a/hgext/record.py
> +++ b/hgext/record.py
> @@ -355,8 +355,8 @@
>                 applied[chunk.filename()].append(chunk)
>             else:
>                 fixoffset += chunk.removed - chunk.added
> -    return reduce(operator.add, [h for h in applied.itervalues()
> -                                 if h[0].special() or len(h) > 1], [])
> +    return sum([h for h in applied.itervalues()
> +               if h[0].special() or len(h) > 1], [])

Wouldn't it be better to use a generator here, rather than a list? That is, something like:
> +    return sum([h for h in applied.itervalues()
> +               if h[0].special() or len(h) > 1], [])

I seem to recall reading that range() in Py3k is equivalent xrange() in 2.x…

--

Dan Villiom Podlaski Christiansen
danchr at gmail.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1943 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20100702/d06c34d9/attachment.bin>


More information about the Mercurial-devel mailing list