[Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview
Paul Sokolovsky
pmiscml at gmail.com
Tue Jun 7 17:33:50 EDT 2016
More information about the Python-Dev mailing list
Tue Jun 7 17:33:50 EDT 2016
- Previous message (by thread): [Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview
- Next message (by thread): [Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello, On Tue, 07 Jun 2016 13:28:13 -0700 Ethan Furman <ethan at stoneleaf.us> wrote: > Minor changes: updated version numbers, add punctuation. > > The current text seems to take into account Guido's last comments. > > Thoughts before asking for acceptance? > > [] > Deprecation of current "zero-initialised sequence" behaviour > ------------------------------------------------------------ > > Currently, the ``bytes`` and ``bytearray`` constructors accept an > integer argument and interpret it as meaning to create a > zero-initialised sequence of the given size:: > > >>> bytes(3) > b'\x00\x00\x00' > >>> bytearray(3) > bytearray(b'\x00\x00\x00') > > This PEP proposes to deprecate that behaviour in Python 3.6, and > remove it entirely in Python 3.7. Why the desire to break applications of thousands and thousands of people? Besides, bytes(3) behavior is very logical. Everyone who knows what malloc(3) does also knows what bytes(3) does. Who doesn't, can learn, and eventually be grateful that learning Python actually helped them to learn other language as well. [] > Addition of explicit "single byte" constructors > ----------------------------------------------- > > As binary counterparts to the text ``chr`` function, this PEP > proposes the addition of an explicit ``byte`` alternative constructor > as a class method on both ``bytes`` and ``bytearray``:: > > >>> bytes.byte(3) > b'\x03' > >>> bytearray.byte(3) > bytearray(b'\x03') > > These methods will only accept integers in the range 0 to 255 > (inclusive):: > > >>> bytes.byte(512) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > ValueError: bytes must be in range(0, 256) > > >>> bytes.byte(1.0) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: 'float' object cannot be interpreted as an integer > > The documentation of the ``ord`` builtin will be updated to > explicitly note that ``bytes.byte`` is the inverse operation for > binary data, while ``chr`` is the inverse operation for text data. The documentation should probably also mention that bytes.byte(x) is equivalent to x.to_bytes(1, "little"). [] -- Best regards, Paul mailto:pmiscml at gmail.com
- Previous message (by thread): [Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview
- Next message (by thread): [Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list