[Python-Dev] PEP 3144 review.

Stephen J. Turnbull stephen at xemacs.org
Tue Sep 29 11:18:36 CEST 2009

Guido van Rossum writes:

 > I don't doubt that Peter has a use case for denormalized IPNetwork
 > objects.

If you know what it is, would you please describe it, or say "that's
proprietary"?  Peter hasn't done either, despite repeated requests.

 > I do note that if Peter's use case is at all common, reducing the
 > number of classes is a worthy goal, and Python has a bit of a
 > history of preferring a small number of Swiss-army-knife classes
 > over a multitude of simple classes.

Even if Peter's use case turns out to be at all common, two things
bother me a lot.


                   IPv4Network(a) == IPv4Network(b)

has an obvious preferred interpretation as pseudocode.

Second, equality comparison for the "abuse" of a network class to
represent host-with-network-info can be implemented cleanly[1] as

                   x = IPv4Network(a)
                   y = IPv4Network(b)
                   (x.ip, x) == (y.ip, y)

as you've pointed out.  It is self-documenting in that makes it plain
that some things that are not "true networks" are being compared.

         x = IPv4Network(a)
         y = IPv4Network(b)
         (x.network, x.prefixlen) == (y.network, y.prefixlen)
         # alternatively
         # list(x) == list(y)

looks like nothing so much as an incomplete implementation to me.  It
just makes me itch to provide the appropriate definitions of __hash__
and __equal__ for IPv4Network.

Do you feel differently?

[1]  It's clean only if we assume you've accepted the "abuse", of course.

More information about the Python-Dev mailing list