'isimmutable' and 'ImmutableNester'

Chris Angelico rosuav at gmail.com
Tue Nov 12 10:21:00 CET 2013

On Tue, Nov 12, 2013 at 8:12 PM, Frank-Rene Schäfer <fschaef at gmail.com> wrote:
> (1) hash()-ability != immutability (!)
> Proof:
> class X:
>     def __hash__(self): return 0

x == y != y == x


class X:
   def __eq__(self,other): return True
class Y:
   def __eq__(self,other): return False

All you've done is proven that you can subvert things. By fiddling
with __hash__, __eq__, and so on, you can make sets and dicts behave
very oddly. Means nothing.

Fundamentally, your mutability check is going to need some form of
assistance from user-defined classes. That means a class can break
your rules.


More information about the Python-list mailing list