[MERGE] remove has_key() usage
Robey Pointer
robey at lag.net
Wed Aug 30 03:27:23 BST 2006
On 29 Aug 2006, at 14:35, John Arbash Meinel wrote:
> Robey Pointer wrote:
>> I've posted a branch at:
>>
>> http://www.lag.net/~robey/code/bzr.dev.no_has_key/
>>
>> which removes the remaining usage of [dict].has_key() that I found in
>> bzr.dev. No new features were added, no bugs were fixed, and nothing
>> really was accomplished except housekeeping. It just kept me busy on
>> the train. :)
>>
>> Patch attached for review.
>
> Is there any particular reason why 'x in foo' is better than
> 'foo.has_key(x)'? I suppose 'in' is supported by more than just dicts
> (sets, lists, etc).
> Just wondering if there is some python advice that I haven't heard of.
I just found out this week: "has_key" has been deprecated for a
while, in favor of the "x in y" syntax. Although it's too early to
be very concerned about it, has_key() will also be gone in python 3.0.
My main motivation was just to update the code style to what is
considered "modern" python. I'll admit to also finding "x in y" more
readable than "y.has_key(x)".
In the branch, I also fixed the 'return' statements, to use explicit
parens.
I may try the same thing with replacing hasattr(), unless this kind
of janitorial work is annoying people.
robey
More information about the bazaar
mailing list