This won’t work because a type is determined to be unhashable only if its __hash__ attribute is None. This means that the __hash__ attribute of an unhashable mutable type can’t be made a dynamic method to make an instance hashable when frozen.
Yes, I think this is the way to go, and to make isinstance(obj, Hashable) work for frozen objects we can make changes to abc and collections.abc such that:
abc.ABCMetaoffers not just a__subclasshook__but also an__instancehook__that is called by its__instancecheck__before falling back to calling__subclasscheck__.collections.abc.Hashableoverrides the__instancehook__to look fortype(obj).__frozen_hash__ifisfrozen(obj)is true.
This allows isinstance(obj, Hashable) to take the state of the instance itself into account. Without the change it currently can only check its type.