I wrote: > [1] I subtlely switched language from "side effect free" to "idempotent" > here because caching *IS* acceptable in __hash__ mehtods. If you're > not paying close attention I probably got away with it.
Andrew Koenig responds: > I picked it up before seeing the footnote :-) Yeah... I have to keep in mind that the readers of python-dev and python-3000 are a lot sharper than most folks I correspond with. Andrew again: > I can think of two troublesome cases; there may be others I haven't thought > of. > > 1) An object x with a component y that might be hashable. x is hashable > apart from x.y, but hashing x for the first time has side effects, so the > value is cached. The hash of x depends partly on the hash of x.y. [...] > 2) An object for which computing the hash for the first time requires human > action. In both cases, __hash__ is not idempotent, and is thus an abomination. Case 1 is a perverse programmer -- well known to be capable of abominations. Case 2 sounds like a made-up example... can you think of anything real which behaves this way? (For instance: the file type doesn't even though it might, and I presume this is intentional.) -- Michael Chermside _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com