1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

memoized: detect hashability by catching TypeError

This is a fix for

https://github.com/ARM-software/devlib/issues/60

Apprently, being an instance of Hashable does not mean that the object
is, in fact, hashable. So rather than testing for hashability, try to
hash the object and handle the potential error by falling back to the
old method.
This commit is contained in:
Sergei Trofimov 2016-10-06 08:44:42 +01:00
parent 09ec88e946
commit cae239d1dc

View File

@ -33,7 +33,6 @@ import ctypes
from operator import itemgetter
from itertools import groupby
from functools import partial
from collections import Hashable
import wrapt
@ -558,9 +557,9 @@ def __get_memo_id(obj):
ID string.
"""
obj_id = id(obj)
if isinstance(obj, Hashable):
try:
return '{}/{}'.format(obj_id, hash(obj))
else:
except TypeError: # obj is not hashable
obj_pyobj = ctypes.cast(obj_id, ctypes.py_object)
# TODO: Note: there is still a possibility of a clash here. If Two
# different objects get assigned the same ID, an are large and are