On Tue, Aug 10, 2021 at 3:00 PM <raymond.hettinger@gmail.com> wrote:
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. 

I didn't read it that way, but if so, please no, I"d rather see the former use cases discouraged. ISTM that the Py2 string handling is still needed for working with mixed binary / text data -- but that should be a pretty specialized use case. spelling the way to create a byte, byte() sure makes more sense in any other context.
... anything where a C programmer would an array of unsigned chars).

or any programmer would use an array of unsigned 8bit integers :-) numpy spells it: `np.uint8`, and the the type in the C99 stdint.h is `uint8_t`. My point is that for anyone not an "old time" C programmer, or even a Python2 programmer, the  "character is an unsigned 8 bit int" concept is alien and confusing, not a helpful mnemonic.
For example, creating a single byte with bytes([0x1f]) isn't pleasant, obvious, or fast.

no, though bytes([31]) isn't horrible ;-)   (despite coding for over four decades, I'm still not comfortable with hex notation)

I say it's not horrible, because bytes is a Sequence of bytes (or integer values between 0 and 255), initializing it with an iterable seems pretty reasonable, that's how we initialize most (all?) other sequences after all. And compatible with array.array and numpy arrays.


Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython