[Python-Dev] PEP 414 - Unicode Literals for Python 3

Giampaolo Rodolà g.rodola at gmail.com
Mon Feb 27 12:34:55 CET 2012


Il 25 febbraio 2012 21:23, Armin Ronacher
<armin.ronacher at active-4.com> ha scritto:
> Hi,
>
> I just uploaded PEP 414 which proposes am optional 'u' prefix for string
> literals for Python 3.
>
> You can read the PEP online: http://www.python.org/dev/peps/pep-0414/
>
> This is a followup to the discussion about this topic here on the
> mailinglist and on twitter/IRC over the last few weeks.
>
>
> Regards,
> Armin

If the main point of this proposal is avoiding an explicit 2to3 run on
account of 2to3 being too slow then I'm -1.
That should be fixed at 2to3 level, not at python syntax level.
A common strategy to distribute code able to run on both python 2 and
python 3 is using the following hack in setup.py:
http://docs.python.org/dev/howto/pyporting.html#during-installation
That's what I used in psutil and it works just fine. Also, I believe
it's the *right* strategy as it lets you freely write python 2 code
and avoid using ugly hacks such as "sys.exc_info()[1]" and "if PY3:
..." all around the place.
2to3 might be slow but introducing workarounds encouraging not to use
it is only going to cause a proliferation of ugly and hackish code in
the python ecosystem.

Now, psutil is a relatively small project and the 2to3 conversion
doesn't take much time. Having users "unawarely" run 2to3 at
installation time is an acceptable burden in terms of speed.
That's going to be different on larger code bases such as Twisted's.

One way to fix that might be making 2to3 generate and rely on a
"2to3.diff" file containing all the differences.
That would be generated the first time "python setup.py build/install"
is run and then partially re-calculated every time a file is modified.
Third-party library vendors can include 2to3.diff as part of the
tarball they distribute so that the end user won't experience any slow
down deriving from the 2to3 conversion.


--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/
http://code.google.com/p/pysendfile/


More information about the Python-Dev mailing list