I recommend removing the "discouragement" from writing "bytes(10)".  That is 
merely stylistic.  As long as we support the API, it is valid Python.  In the 
contexts where it is currently used, it tends to be clear about what it is 
doing:  buffer = bytearray(bufsize). That doesn't need to be discouraged.

Also, I concur the with SC comment that the singular of bytearray() or bytes() 
is byte(), not bchr().  Practically what people want here is an efficient 
literal that is easier to write than:  b'\x1F'.   I don't think bchr() meets 
that need. Neither bchr(0x1f) or bytearray.fromint(0x1f) are fast (not a 
literal) nor are they easier to read or type.

The history of bytes/bytearray is a dual-purpose view.  It can be used in a 
string-like way to emulate Python 2 string handling (hence all the usual string 
methods and a repr that displays in a string-like fashion).  It can also be 
used as an array of numbers, 0 to 255 (hence the list methods and having an 
iterator of ints).  ISTM that the authors of this PEP reject or want to 
discourage the latter use cases.  

This is disappointing because often the only reasonable way to manipulate 
binary data is with bytearrays.  A user could switch to array.array() or a 
numpy.array, but that is unnecessarily inconvenient given that we already have 
a nice builtin type that means the need (for images, crypto hashes, 
compression, bloom filters, or anything where a C programmer would an array of 
unsigned chars).

Given that bytes/bytearray is already an uncomfortable hybrid of string and 
list APIs for binary data, I don't think the competing views and APIs will be 
disentangled by adding methods that duplicate functionality that already 
exists.   Instead, I recommend that the PEP focus on one or two cases where 
methods could be added that simplify any common tasks that are currently 
awkward.  For example, creating a single byte with bytes([0x1f]) isn't 
pleasant, obvious, or fast.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/OKILIXKK7F6BHDRTFRGUFXXUDNNZW3BL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to