Serhiy Storchaka added the comment: > Which virtually no one follows :(
Sad. But adding bytes.frombuffer() wouldn't make it magically used. If you are aware of the problem, you can use the above two-liner as well as bytes.frombuffer(). You even can use it in the current code with older Python releases, unlike to bytes.frombuffer() which would need 3.7. > Any protocol parsing code has a lot of slicing. How much code you expect to update with bytes.frombuffer()? And why not use the above two-liner instead? > > There is also a problem with returned type for subclasses (this is always > > a problem for alternate constructors). > Good point. How do we usually solve this in CPython? It is deemed that returning an instance of a subclass is more preferable. Otherwise you could use separate function rather of a class method. But it is not easy. You need either pass a memoryview or bytes instance to class constructor, or (only for mutable arrays) create an empty instance and concatenate a buffer to it. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29178> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com