[Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

Nick Coghlan ncoghlan at gmail.com
Sun Mar 30 01:28:33 CET 2014


On 30 March 2014 05:01, Gregory P. Smith <greg at krypto.org> wrote:
>
>
>
> On Thu, Mar 27, 2014 at 3:47 AM, Victor Stinner <victor.stinner at gmail.com>
> wrote:
>>
>> The PEP 461 looks good to me. It's a nice addition to Python 3.5 and
>> the PEP is well defined.
>
>
> +1
>
>>
>> I can help to implement it. Maybe, it would be nice to provide an
>> implementation as a third-party party module on PyPI for Python
>> 2.6-3.4.
>
>
> That is possible and would enable bytes formatting on earlier 3.x versions.
> I'm not sure if there is any value in backporting to 2.x as those already
> have such formatting with Python 2's str.__mod__ % operator.
>
> Though I don't know what it'd look like as an API as a module.
> Brainstorming: It'd either involve function calls to format instead of % or
> a container class to wrap format strings in with a __mod__ method that calls
> the bytes formatting code instead of native str % formatting when needed.

The "future" project already contains a full backport of a true bytes
type, rather than relying on Python 2 str objects:
http://python-future.org/what_else.html#bytes

It seems to me that the easiest way to make any forthcoming Python 3.5
enhancements (both binary interpolation and the other cleanups we are
discussing over on Python ideas) available to single source 2/3 code
bases is to commit to an API freeze for *those particular builtins*
early, and then update "future" accordingly.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list