[prev in list] [next in list] [prev in thread] [next in thread] 

List:       spacewalk-devel
Subject:    [Spacewalk-devel] [PATCH 5/6] Python: fixed UserDictCase behaviour when key is not found
From:       Flavio Castelli <fcastelli () suse ! com>
Date:       2013-10-04 8:55:05
Message-ID: 1380876906-12421-6-git-send-email-fcastelli () suse ! com
[Download RAW message or body]

The `UserDictCase` class is a dictionary with case insensitive keys.
Since it's inherited from `UserDict` it can be passed to method/functions
expecting a "classic" python dictionary.

Unfortunately `UserDictCase` behaved in a different way when the specified key
was not found: rather than raising a `KeyError` exception it just returned
`None`. That broke duck typing in some places where a `KeyError` was
expected and it also hid errors in other parts of the code (because no exception
was being raised).

This commit ensures `UserDictCase` has the same behaviour of python's
dictionary. The change could break some parts of the code which took
this bug as a feature.

The python unit tests under 'backend/test' and 'backend/satellite_tools' are
still passing.
---
 client/rhel/rhnlib/rhn/UserDictCase.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/client/rhel/rhnlib/rhn/UserDictCase.py b/client/rhel/rhnlib/rhn/UserDictCase.py
index cb55674..c4b8dd6 100644
--- a/client/rhel/rhnlib/rhn/UserDictCase.py
+++ b/client/rhel/rhnlib/rhn/UserDictCase.py
@@ -41,8 +41,6 @@ class UserDictCase(UserDict):
 
     def __getitem__(self, key):
         key = self.__lower_string(key)
-        if not self.data.has_key(key):
-            return None
         return self.data[key]
 
     get = __getitem__
-- 
1.8.1.4

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic