Change in vdsm[master]: mount: Better and simpler __hash__

nsoffer at redhat.com nsoffer at redhat.com
Fri Jul 24 19:28:54 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: mount: Better and simpler __hash__
......................................................................

mount: Better and simpler __hash__

Mixing type(self) in a hash is not a good idea, all instance of old
style class have the same type. It is better to use the __class__
attribute to get the hash of the class.

The hash values were mixed in a poor way. There is no need to implement
when we can use the hash function of the tuple object, which does a
better job.

Change-Id: I6030c441c7137d65f4038d86e9813719429250c0
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M vdsm/storage/mount.py
1 file changed, 1 insertion(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/43978/1

diff --git a/vdsm/storage/mount.py b/vdsm/storage/mount.py
index e818fd1..1626a26 100644
--- a/vdsm/storage/mount.py
+++ b/vdsm/storage/mount.py
@@ -206,10 +206,7 @@
         return not self == other
 
     def __hash__(self):
-        hsh = hash(type(self))
-        hsh ^= hash(self.fs_spec)
-        hsh ^= hash(self.fs_file)
-        return hsh
+        return hash((self.__class__, self.fs_spec, self.fs_file))
 
     def mount(self, mntOpts=None, vfstype=None, timeout=None, cgroup=None):
         cmd = [constants.EXT_MOUNT]


-- 
To view, visit https://gerrit.ovirt.org/43978
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6030c441c7137d65f4038d86e9813719429250c0
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list