[Python-ideas] bytes indexing behavior

Neil Schemenauer nas-pythonideas at arctrix.com
Mon Jun 6 15:35:30 EDT 2016


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


More information about the Python-ideas mailing list