arrange __getattr__ to behave normally
@@ -42,7 +42,8 @@ except AttributeError:
class Map(dict):
"""
Example:
- m = Map({'first_name': 'Eduardo'}, last_name='Pool', age=24, sports=['Soccer'])
+ m = Map({'first_name': 'Eduardo'}, last_name='Pool', age=24,
+ sports=['Soccer'])
"""
def __init__(self, *args, **kwargs):
super(Map, self).__init__(*args, **kwargs)
@@ -56,7 +57,10 @@ class Map(dict):
self[k] = v
def __getattr__(self, attr):
+ if attr in self:
return self.get(attr)
+ else:
+ raise AttributeError
def __setattr__(self, key, value):
self.__setitem__(key, value)
@@ -78,11 +82,11 @@ class Map(dict):
def __setstate__(self, state):
for key in state:
self.__setattr__(key, state[key])
+
def __hash__(self):
return hash(tuple(sorted(self.items())))
-
class AlbumInfo(Map):
"""Describes a canonical release that may be used to match a release
in the library. Consists of these data members:
