[MERGE] remove has_key() usage

John Arbash Meinel john at arbash-meinel.com
Tue Aug 29 22:35:05 BST 2006


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.
> 
> robey
> 
> 

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.


...

>  
>      def has_id(self, file_id):
> -        return self._byid.has_key(file_id)
> +        return file_id in self._byid

I think for a return value, I prefer:

return (file_id in self._byid)

Because I think it makes it a little bit clearer that you aren't
returning the file_id.


>  
>      def rename(self, file_id, new_parent_id, new_name):
>          """Move a file within the inventory.
> 
> === modified file bzrlib/knit.py
> --- bzrlib/knit.py
> +++ bzrlib/knit.py
> @@ -1255,7 +1255,7 @@
>          
>      def has_version(self, version_id):
>          """True if the version is in the index."""
> -        return self._cache.has_key(version_id)
> +        return version_id in self._cache
>  
>      def get_position(self, version_id):
>          """Return data position and size of specified version."""
> 

Anyway, if you can justify why we wouldn't want to use has_key() it
looks okay.

John
=:->



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060829/37be4e83/attachment.pgp 


More information about the bazaar mailing list