Python 2 to 3 conversion - embrace the pain

Chris Angelico rosuav at gmail.com
Mon Mar 16 04:51:50 EDT 2015


On Mon, Mar 16, 2015 at 6:56 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> [ a whole lot of stuff that I agree with, and then ... ]
> Module renames could be handled via stub modules. Even Unicode strings could
> hypothetically have been added via a __future__ import.

This part I don't agree with. The problem with the Unicode / bytes
distinction is that library functions are written to expect one or the
other. Even in the stdlib, issues have been found, and the future
import can't solve that. You can already create Unicode strings in
Py2, with the u"..." syntax; you can even make it the default with
unicode_literals; but you can't magically make functions in other
modules cope with the other type of string. (Not with a __future__
import, anyway. Maybe "from __fairy_godmother__ import pumpkin"?)
Whenever it's easy, I encourage people to write their Py2 code to be
Py3-compatible - put parens around their print calls, be clear about
integer vs float division, use the "as" syntax for exception catching
- but I don't encourage from __future__ import unicode_literals,
because it tends to just move problems around rather than solving
them.

ChrisA



More information about the Python-list mailing list