Le Wed, 19 Aug 2009 08:35:15 -0700, Peter Moody a écrit :
does it mean that the objects are mutable? Would it make sense to make them immutable and therefore hashable (such as, e.g., datetime objects)?
that's a good point. I'll implement __hash__ in the BaseIP class.
It is a common practice that only immutable objects define a meaningful __hash__ method. The reason is that dicts and sets (and perhaps other structures) cache the hash value instead of calling __hash__ again and again. If you stick a mutable with a meaningful __hash__ in a dict, and then modify the mutable object, lookups will give the wrong results (they will be based on the old, stale hash value). It seems to me that hashability is a more desireable property of IP objects than modifiability. I don't see any reason to modify an IP object after having created it (rather than creating a new object). Regards Antoine.