On Wed, Dec 26, 2018, 02:19 Andrew Svetlov <andrew.svet...@gmail.com wrote:

>
> Also I'm thinking about type annotations in typeshed.
> Now the type is Union[array[int], bytes, bytearray, memoryview]
> Should it be Union[io.BinaryIO, array[int], bytes, bytearray, memoryview] ?
>

Yeah, trying to support both buffers and file-like objects in the same
function seems like a clearly bad idea. If we do this at all it should be
by adding new convenience functions/methods that take file-like objects
exclusively, like the ones several people posted on the thread.

I don't really have an opinion on whether this is worth doing at all. I
guess I can think of some arguments against: Packing/unpacking multiple
structs to the same file-like object may be less efficient than using a
single buffer + a single call to read/write. And it's unfortunate that the
obvious pack_into/unpack_from names are already taken. And it's only 2
lines of code to write your own helpers. But none of these are particularly
strong arguments either, and clearly some people would find them handy.

-n
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to