[PATCH 1 of 9] record extension: removed 'has_key' usage

Nicolas Dumazet nicdumz at gmail.com
Mon Jul 19 20:04:35 CDT 2010


2010/7/20 Greg Ward <greg-hg at gerg.ca>:
> On Wed, Jul 14, 2010 at 10:18 PM, Renato Cunha <renatoc at gmail.com> wrote:
>> # HG changeset patch
>> # User Renato Cunha <renatoc at gmail.com>
>> # Date 1279159109 10800
>> # Branch stable
>> # Node ID 21e794287623b1ae539d0213be2c8720797e256d
>> # Parent  6f44bd4cc4f2277fcdc0a5d3e7f58c26234a70cf
>> record extension: removed 'has_key' usage
>>
>> Py3k has removed the dictionary has_key method. This patch implements a one
>> argument function that can be used as a callback by hg.revert in the record
>> extension.
>>
>> diff --git a/hgext/record.py b/hgext/record.py
>> --- a/hgext/record.py
>> +++ b/hgext/record.py
>> @@ -485,7 +485,8 @@
>>
>>             # 3a. apply filtered patch to clean repo  (clean)
>>             if backups:
>> -                hg.revert(repo, repo.dirstate.parents()[0], backups.has_key)
>> +                hg.revert(repo, repo.dirstate.parents()[0],
>> +                          lambda key: key in backups)
>
> I'm 95% positive that you can just pass backups.__contains__ instead
> of backup.has_key.  No need for a lambda which just really just an
> inefficient way of accessing backups.__contains__.  Disclaimer: that's
> based on reading the Python 2.7 source code, not on actually testing
> it with 2.4 .. 3.1.
>

Yes, __contains__ works and looks like the good way (tm)

Regards

> Greg
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>



-- 
Nicolas Dumazet — NicDumZ


More information about the Mercurial-devel mailing list