how to test for atomicity/mutability/hashability?

Chris Rebert clp2 at rebertia.com
Thu Oct 7 16:02:42 EDT 2010


On Thu, Oct 7, 2010 at 12:13 PM, kj <no.email at please.post> wrote:
<snip>
> It would facilitate the implementation of t() to have a simple test
> for mutability.  Is there one?

Non-default hashability is an approximate heuristic:

def is_immutable(x):
    try:
        hash(x)
    except TypeError:
        return False
    else:
        klass = type(x)
        return klass is object or klass.__hash__ is not object.__hash__

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list