On Thu, Oct 7, 2010 at 2:28 PM, Christian Heimes <li...@cheimes.de> wrote: > Am 07.10.2010 22:02, schrieb Chris Rebert: >> On Thu, Oct 7, 2010 at 12:13 PM, kj <no.em...@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 -- http://mail.python.org/mailman/listinfo/python-list