def _prepare_memoization_key(args, kwargs):
    """
    Make a tuple of arguments which can be used as a key
    for a memoized function's lookup_table. If some object can't be hashed
    then used its __repr__ instead.
    """
    key_list = []
    for arg in args:
        try:
            hash(arg)
            key_list.append(arg)
        except:
            key_list.append(repr(arg))
    for (k, v) in kwargs.items():
        try:
            hash(k)
            hash(v)
            key_list.append((k, v))
        except:
            key_list.append((repr(k), repr(v)))
    return tuple(key_list)
Make a tuple of arguments which can be used as a key
    for a memoized function's lookup_table. If some object can't be hashed
    then used its __repr__ instead.