[Python-Dev] PEP 351, the freeze protocol
Josiah Carlson
jcarlson at uci.edu
Tue Oct 25 21:04:33 CEST 2005
Nick Coghlan <ncoghlan at gmail.com> wrote:
>
> Josiah Carlson wrote:
> > Nick Coghlan <ncoghlan at gmail.com> wrote:
> >> I think having dicts and sets automatically invoke freeze would be a mistake,
> >> because at least one of the following two cases would behave unexpectedly:
> >
> > I'm pretty sure that the PEP was only aslomg if one would freeze the
> > contents of dicts IF the dict was being frozen.
> >
> > That is, which of the following should be the case:
> > freeze({1:[2,3,4]}) -> {1:[2,3,4]}
> > freeze({1:[2,3,4]}) -> xdict(1=(2,3,4))
>
> I believe the choices you intended are:
> freeze({1:[2,3,4]}) -> imdict(1=[2,3,4])
> freeze({1:[2,3,4]}) -> imdict(1=(2,3,4))
>
> Regardless, that question makes a lot more sense (and looking at the PEP
> again, I realised I simply read it wrong the first time).
>
> For containers where equality depends on the contents of the container (i.e.,
> all the builtin ones), I don't see how it is possible to implement a sensible
> hash function without freezing the contents as well - otherwise your immutable
> isn't particularly immutable.
>
> Consider what would happen if list "__freeze__" simply returned a tuple
> version of itself - you have a __freeze__ method which returns a potentially
> unhashable object!
I agree completely, hence my original statement on 10/23: "it is of my
opinion that a container which is frozen should have its contents frozen
as well."
- Josiah
More information about the Python-Dev
mailing list