def msgpack_encode_hashable(x): if not isinstance(x, collections.Hashable): raise ValueError(x) return messagepack.packb(x)