[Distutils] multiple backports of ipaddress and a world of pain

Philipp Hagemeister phihag at phihag.de
Tue Feb 16 17:31:22 EST 2016


Code that uses py2-ipaddress will break upon migrating to Python 3, and
potentially in really subtle ways. For instance,

import py2_ipaddress as ipaddress
ipaddress.ip_address(b'\x3a\x3a\x31\x32')
ipaddress.ip_address(open('file', 'rb').read(4))

has different semantics in Python 2 and Python 3. Also note that if you
actually want to generate an ipaddress object from a binary
representation, py2-ipaddress' "solution"
ipaddress.ip_address(bytearray(b'\xff\x00\x00\x01'))
will break as well under Python 3, but at least it will throw an
exception and not silently do something different.

Therefore, code that uses py2-ipaddress needs to be fixed anyways in
order to work correctly under Python 3 - might as well do it now.

py2-ipaddress' API is incompatible with the ipaddress from the stdlib,
so I don't think it should claim the module name ipaddress in the first
place. Why one would actively introduce incompatibilities between Python
2 and Python 3 *after Python 3 has long been released* is beyond my
understanding anyways.

Specifically for django-netfields, a workaround is to always use
character strings (unicode type in Python 2, str in Python 3).

Greetings from Düsseldorf,

Philipp

On 16.02.2016 19:37, Chris Withers wrote:
> Hi All,
> 
> (Apologies for copying in the maintainers of the two backports and
> django-netfields directly, I'm not sure you're on this distutils list...)
> 
> This is painful and horrible, and I wish pip would prevent
> modules/packages with the same name being installed by different
> distributions at the same time, but even if it did, that would just
> force something to happen rather than this:
> 
> So, RHEL7, for worse or worse, ships with Python 2.7.5. That means to
> keep pip happy, you need to do these dances in all the virtualenvs you
> create:
> 
> http://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning
> 
> http://urllib3.readthedocs.org/en/latest/security.html#pyopenssl
> 
> One of those extra packages drags in this backport:
> 
> https://pypi.python.org/pypi/ipaddress
> 
> Yay! Now we have a happy pip talking to both PyPI and our internal DevPI
> server!
> 
> Right, so in a Django project I need to use
> https://pypi.python.org/pypi/django-netfields. This, however, chooses
> this backport instead:
> 
> https://pypi.python.org/pypi/py2-ipaddress
> 
> So, now we have two packages installing ipaddress.py, except they're two
> very different versions and make different assumptions about what to do
> with Python 2 strings.
> 
> What should happen here? (other than me crying a lot...)
> 
> Chris
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20160216/39e90d52/attachment-0001.sig>


More information about the Distutils-SIG mailing list