how to test for atomicity/mutability/hashability?

Chris Rebert clp2 at rebertia.com
Thu Oct 7 18:43:54 EDT 2010


On Thu, Oct 7, 2010 at 2:28 PM, Christian Heimes <lists at cheimes.de> wrote:
> Am 07.10.2010 22:02, schrieb Chris Rebert:
>> 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:
>
> Except that every user defined class is hashable and mutable by default ;)
>
>>>> class Example(object):
> ...     pass
> ...
>>>> example = Example()
>>>> hash(example)
> 139810551284624
>>>> example.__dict__
> {}
>>>> example.egg = "spam"
>>>> example.__dict__
> {'egg': 'spam'}

Hence exactly why I said *non-default* hashability (i.e. the object is
hashable, but does not use the default implementation which you point
out exists):

>>> is_immutable(Example())
False

Not that the heuristic I suggested is infallible or anything though.

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



More information about the Python-list mailing list