Add __hash__ functions where necessary
According to [1], A class that overrides __eq__() and does not define __hash__() will have its __hash__() implicitly set to None. When the __hash__() method of a class is None, instances of the class will raise an appropriate TypeError when a program attempts to retrieve their hash value, and will also be correctly identified as unhashable when checking isinstance(obj, collections.Hashable). A few other classes also implement __eq__ but we don't seem to use them anywhere as keys in dictionaries, so they don't need to implement the __hash__ function yet. [1] https://docs.python.org/3.4/reference/datamodel.html?highlight=hash#object.__hash__ partial blueprint heat-python34-support Change-Id: Idf24d462f386927496950e65a24e41b9aef69281
This commit is contained in:
parent
cdfcd61a1d
commit
46233d2c2a
|
@ -125,6 +125,9 @@ class Function(object):
|
|||
return NotImplemented
|
||||
return not eq
|
||||
|
||||
def __hash__(self):
|
||||
return id(self)
|
||||
|
||||
|
||||
def resolve(snippet):
|
||||
while isinstance(snippet, Function):
|
||||
|
|
|
@ -296,6 +296,9 @@ class Resource(object):
|
|||
return result
|
||||
return not result
|
||||
|
||||
def __hash__(self):
|
||||
return id(self)
|
||||
|
||||
def metadata_get(self, refresh=False):
|
||||
if refresh:
|
||||
self._rsrc_metadata = None
|
||||
|
|
|
@ -395,6 +395,13 @@ class ResourceDefinition(ResourceDefinitionCore, collections.Mapping):
|
|||
|
||||
raise KeyError(key)
|
||||
|
||||
def __hash__(self):
|
||||
"""
|
||||
Return a hash of the ResourceDefinition object.
|
||||
"""
|
||||
warnings.warn(self._deprecation_msg, DeprecationWarning)
|
||||
return super(ResourceDefinition, self).__hash__()
|
||||
|
||||
def __len__(self):
|
||||
"""
|
||||
Return the number of available CFN template keys.
|
||||
|
|
|
@ -126,6 +126,9 @@ class PhysName(object):
|
|||
# ignore the stack portion of the name, as it may have been truncated
|
||||
return res == self.res
|
||||
|
||||
def __hash__(self):
|
||||
return id(self)
|
||||
|
||||
def __ne__(self, physical_name):
|
||||
return not self.__eq__(physical_name)
|
||||
|
||||
|
|
Loading…
Reference in New Issue