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@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)