A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-August/091250.html below:

IP Address Manipulation Library for the Python Standard Library

[Python-Dev] PEP 3144: IP Address Manipulation Library for the Python Standard Library [Python-Dev] PEP 3144: IP Address Manipulation Library for the Python Standard LibraryAntoine Pitrou solipsis at pitrou.net
Wed Aug 19 18:29:08 CEST 2009
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.


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4