> So how do you figure out whether something's immutable or not? Are you
> going to ask the object itself? If so, stick with __hash__, and just
> follow the rule that mutable objects aren't hashable - which is, if
> I'm not mistaken, how things already are. And if not, then how? How
> will you know
> 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.
To the contrary, it means everything about what 'isimmutable' could
contribute: security against advert or inadvert insertion of
(1) hash()-ability != immutability (!)
Proof:
class X:
def __hash__(self): return 0
def pseudo_isimmutable(this):
try:
hash(this)
return True
except TypeError:
return False
shapeshifter = (1, 2, X())
print pseudo_isimmutable(shapeshifter)
shapeshifter[2].chan
A tuple is immutable but it may contain mutable objects. In larger
hierarchies of objects it may become less obvious whether down
the lines, there is some mutable object somewhere in the data tree.
One can define a recursive function to check for immutability
manually. However first, it may not be
I prepared a PEP and was wondering what your thoughts are about it:
PEP:
Title: ``isimmutable(Obj)`` and/or ``ImmutableNester``
Version:
Last-Modified:
Author: Frank-Rene Schaefer, fsch...@users.sourceforge.net
* BDFL-Delegate:
* Discussions-To: f