[Python-Dev] PEP 3144 review.

Scott Dial scott+python-dev at scottdial.com
Wed Sep 16 01:34:09 CEST 2009


R. David Murray wrote:
> On Tue, 15 Sep 2009 at 21:58, Antoine Pitrou wrote:
>> Le mardi 15 septembre 2009 à 15:48 -0400, R. David Murray a écrit :
>>> However, I do not think
>>> that the proposed API should accept, eg, IPv4Network('192.168.1.1/24')
>>> as valid.  That's just too confusing and error prone.
>>
>> Indeed, it should throw some kind of ValueError instead.
> 
> Peter, what do you think?

This change would have to be dependent on Antoine's suggestion of:

    >>> addr, net = parse_address_with_mask('192.168.1.1/24')
    >>> addr == IPv4Address('192.168.1.1')
    True
    >>> net == IPv4Network('192.168.1.0/24')
    True

Otherwise, I am ok with this change too. It resloves the weird duality
of IPv4Network. And as RDM says, anyone who wants the
IPv4AddressWithNetwork functionality can just role it themselves. At the
moment of iteration, you have access to what network it is and can build
your own IPv4AddressWithNetwork objects.

net = IPv4Network('10.0.0.0/24')
netaddrs = []
for addr in net:
    netaddrs.append(IPv4AddressWithNetwork(addr, net))

I guess I am ok with this. It seems sub-optimal (why not just return a
IPv4AddressWithNetwork to begin with?) but I suppose it is no less
efficient since the same objects would be constructed.

-- 
Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu


More information about the Python-Dev mailing list