[Python-ideas] bytes indexing behavior

Guido van Rossum guido at python.org
Mon Jun 6 16:28:12 EDT 2016


I think the approach using a new method for the old behavior is workable.
Maybe we should add another (temporary) new method for the new behavior.

The magic object approach is too magical.

We should do the same for bytearray and memoryview.

On Mon, Jun 6, 2016 at 12:35 PM, Neil Schemenauer <
nas-pythonideas at arctrix.com> wrote:

> On 2016-06-04, Guido van Rossum wrote:
> > The bytes -> int behavior is widely considered a mistake. We're just
> > not able to fix it without yet another round of layoffs ^W
> > deprecations. And I'm not ready for that -- not even Python 4 should
> > be allowed to change this unilaterally. Though maybe we could do
> > something with a __future__ import.
>
> Maybe the following would work:
>
> - add a new method to 'bytes' that returns a view object with the
>   current index/iteration behavior
>
> - enable a deprecation warning for code that uses indexing/iteration
>   on bytes
>
> - when sufficient time has passed, revert to Python 2 behavior for
>   indexing/iteration
>
> Another, probably crazy and unworkable idea:
>
> - have bytes indexing/iteration return a special type that behaves like
>   an int or length one byte.
>
> - ord() of this object would return a real int
>
> - code that utilizes this object as an int would generate a warning
>   (suggest adding an ord() call to fix code).
>
> - eventually just return length one byte strings
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160606/92cbdd78/attachment.html>


More information about the Python-ideas mailing list