On Mon, Sep 28, 2009 at 7:42 AM, Dj Gilcrease <digitalx...@gmail.com> wrote:
> On Mon, Sep 28, 2009 at 8:04 AM, Daniel Stutzbach
> <dan...@stutzbachenterprises.com> wrote:
>> On Mon, Sep 28, 2009 at 7:24 AM, Nick Coghlan <ncogh...@gmail.com> wrote:
>>>
>>> I should note that I've softened my position slightly from what I posted
>>> yesterday. I could live with the following compromise:
>>>
>>>    >>> x = IPv4Network('192.168.1.1/24')
>>>    >>> y = IPv4Network('192.168.1.0/24')
>>>    >>> x == y # Equality is the part I really want to see changed
>>>    True
>>>    >>> x.ip
>>>    IPv4Address('192.168.1.1')
>>>    >>> y.ip
>>>    IPv4Address('192.168.1.0')
>>
>> With those semantics, IPv4Network objects with distinct IP addresses (but
>> the same network) could no longer be stored in a dictionary or set.  IMO, it
>> is a little counter-intuitive for objects to compare equal yet have
>> different properties.  I don't think this is a good compromise.
>
> Thats not true, the patch I submitted
> http://codereview.appspot.com/124057 still allows the networks to be
> included in a set or as a dict key
>
>>>> net1 = IPNetwork("10.1.2.3/24")
>>>> net2 = IPNetwork("10.1.2.0/24")
>>>> print hash(net1) == hash(net2)
> False
>>>> print net1 == net2
> True

Hold it right there! That's wrong. You can't have two objects that
compare equal but whose hashes differ. It will break dict lookup. The
other way around is fine: two objects may differ and still have the
same hash.

>>>> test = {net1: "something", net2: "something else"}
>>>> print test
> {IPv4Network('10.1.2.0/24'): 'something else',
> IPv4Network('10.1.2.3/24'): 'something'}
>>>> test2 = set([net1, net2])
>>>> print test2
> set([IPv4Network('10.1.2.0/24'), IPv4Network('10.1.2.3/24')])
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: 
> http://mail.python.org/mailman/options/python-dev/guido%40python.org
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to