From c843eeabc2938fc6528e90befdfc3ea60ebe1a22 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Thu, 17 Nov 2016 15:53:43 +0100 Subject: [PATCH] Performance improvement using in-operator for hash lookups Just a small cleanup for the existing occurrences. Using the in-operator for hash lookups is faster than using .has_key() http://stackoverflow.com/questions/1323410/has-key-or-in --- lib/ansible/modules/packaging/os/rhn_register.py | 2 +- lib/ansible/modules/system/user.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/packaging/os/rhn_register.py b/lib/ansible/modules/packaging/os/rhn_register.py index 06f3190e626..8e9ae4a9f18 100644 --- a/lib/ansible/modules/packaging/os/rhn_register.py +++ b/lib/ansible/modules/packaging/os/rhn_register.py @@ -163,7 +163,7 @@ class Rhn(RegistrationBase): def get_option_default(self, key, default=''): # ignore pep8 W601 errors for this line # setting this to use 'in' does not work in the rhn library - if self.has_key(key): + if key in self: return self[key] else: return default diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py index 09a9cf9101f..0c8e579382c 100644 --- a/lib/ansible/modules/system/user.py +++ b/lib/ansible/modules/system/user.py @@ -1715,7 +1715,7 @@ class DarwinUser(User): self.chown_homedir(int(self.uid), int(self.group), self.home) for field in self.fields: - if self.__dict__.has_key(field[0]) and self.__dict__[field[0]]: + if field[0] in self.__dict__ and self.__dict__[field[0]]: cmd = self._get_dscl() cmd += [ '-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]] @@ -1752,7 +1752,7 @@ class DarwinUser(User): self._make_group_numerical() for field in self.fields: - if self.__dict__.has_key(field[0]) and self.__dict__[field[0]]: + if field[0] in self.__dict__ and self.__dict__[field[0]]: current = self._get_user_property(field[1]) if current is None or current != self.__dict__[field[0]]: cmd = self._get_dscl()