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

Vinay Sajip vinay_sajip at yahoo.co.uk
Tue Feb 28 16:18:29 CET 2012


Nick Coghlan <ncoghlan <at> gmail.com> writes:

> tools. But the existing approaches require that, in order to be
> forward compatible with Python 3, a program must be made *worse* in
> Python 2 (i.e. harder to read and harder to write correctly for
> someone that hasn't learned Python 3 yet). Restoring unicode literal

How so? In the case of string literals, are you saying that it's worse in that
you use 'xxx' instead of u'xxx' for text, and have to add a unicode_literals
import? I don't feel that either of those make a 2.x program worse.

> support in 3.3 is a pragmatic step that allows a lot of code to *just
> work* on Python 3. Most 2.6+ code that still doesn't work on Python 3
> even after this change will be made *better* (or at least not made
> substantially worse) by the additional changes necessary for forward
> compatibility.

Remember, the PEP advocates what it does in the name of a single codebase. If
you want to (or have to) support 3.2 in addition to 3.3, 2.6, 2.7, the PEP does
not work for you. It only works for you if you're interested in 2.6+ and 3.3+.

> Unicode literals are somewhat unique in their impact on porting
> efforts, as they show up *everywhere* in Unicode correct code in
> Python 2. The diffs that will be needed to correctly tag bytestrings
> in such code under Python 2 are tiny compared to those that would be
> needed to strip the u"" prefixes.

But that's a one-time operation using a lib2to3 fixer, and even for a big
project like Django, we're not talking about a lot of time spent on this (at
least, in my experience). Having a good test suite helps catch those byte-string
cases more easily, of course.

Regards,

Vinay Sajip



More information about the Python-Dev mailing list