[Python-Dev] PEP 414

Lennart Regebro regebro at gmail.com
Sat Mar 3 13:29:09 CET 2012


On Sat, Mar 3, 2012 at 11:39, Vinay Sajip <vinay_sajip at yahoo.co.uk> wrote:
> Sorry, I didn't make myself clear. If you import unicode_literals, then in both
> 2.x and 3.x code, an unadorned literal string is text, and a b-adorned literal
> string is bytes. My assertion was based on that assumption - the text (Unicode)
> case then becomes the most common case.

Absolutely.

>> I think there is some misunderstanding here. The binary/unicode/native
>> separation is only possible on Python 2.6 and 2.7 at the moment,
>> unless you use function wrappers like b().
>
> Right, and that is a possible option for 2.5 and earlier: though obviously not a
> desirable one from an aesthetic point of view!
>
> What I meant (and should have said) was: if you can drop support for 2.5 /
> earlier, a lib2to3 fixer-based approach brings your 2.x code into the 3-friendly
> region of 2.x - 2.6 and 2.7. You can then, using the unicode_literals approach,
> arrive at a common codebase for 2.6+ and 3.x which is not slow to run (see my
> other post on ported Django test run performance), and clean (looks just like 3
> code, pretty much, and means the same, as far as string literals are concerned).
> Where you hit native string requirements, apply the wrapper.

Yes, that's a doable solution. Just as the common solution of using
b() and u() wrappers. But these are still more confusing and less
aesthetically pleasing (and insignificantly slower) than supporting
u'' in Python 3.

//Lennart


More information about the Python-Dev mailing list