[Python-Dev] PEP 3144 review.

Nick Coghlan ncoghlan at gmail.com
Mon Sep 28 14:24:55 CEST 2009


R. David Murray wrote:
> On Mon, 28 Sep 2009 at 07:34, R. David Murray wrote:
>> The fundamental divide here is between two behaviors.
>>
>> ipaddr:
>>
>>    > > >  x = IPv4Network('192.168.1.1/24')
>>    > > >  y = IPv4Network('192.168.1.0/24')
>>    > > >  x == y
>>     False
>>    > > >  x.ip
>>     IPv4Address('192.168.1.1')
>>
>> desired:
>>
>>    > > >  x = IPv4Network('192.168.1.1/24')
>>    > > >  y = IPv4Network('192.168.1.0/24')
>>    > > >  x == y
>>     True
>>    > > >  x.ip
>>     Traceback (most recent call last):
>>       File "<stdin>", line 1, in <module>
>>     AttributeError: 'IPv4Network' object has no attribute 'ip'
>>
>> Everything else is pretty much bikeshedding and can be dealt with.  This
>> is fundamental and Peter has indicated he will not change it.
> 
> By the way, I think this is a reasonable position on Peter's part.
> He's got an installed base that expects the current behavior (ie: the
> "field tested module" has this behavior; making this change would produce
> a fundamentally new module that has _not_ been field tested).
> 
> But I also think that the current behavior is not a good behavior for
> a module in the stdlib.

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')

So IPNetwork equality classes would be rendered conceptually coherent
(i.e. list(net1) == list(net2) would imply net1 == net2), but the "Host
with associated network" functionality would also be retained.

To check that the hosts were the same in addition to the network
definition one could easily check the .ip attribute in addition to
checking the networks themselves.

Something I also noticed is that "compare_networks" in the ipaddr
reference implementation doesn't follow the PEP - it defines IPv4
networks as being less than IPv6 networks instead of raising a TypeError.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------


More information about the Python-Dev mailing list