Can you please provide concrete code examples? I am not a data scientist and I don't know all the libraries you are interested in.

Also, the buffer protocol is very low level, I'd worry that the code wouldn't be very safe in practice.

What's wrong with the occasional cast() call or # type: ignore comment?

On Tue, May 19, 2020 at 00:36 René Dudfield <renesd@gmail.com> wrote:
Hi,

to share data, a number of libraries use the buffer protocol(s)[0].
There seems to be a python issue open [1], and a typing issue open [2].

Anyone have better interim solution(s) that work cross-library?
The given work-around in [2] doesn't really work in a number of cases:
Union[bytes, bytearray, memoryview]
Consider if this would work with array.array, or <type 'numpy.ndarray'> or dozens of other libraries buffer protocol friendly types.

As a concrete example, numpy is adding the ndarray to that Union using this [3]:

_BufferType = Union[ndarray, bytes, bytearray, memoryview]

Whilst this supports ndarray, it doesn't scale to the full list of third party types supporting buffer protocol(s) [opencv, pygame, pillow, ...].

Every suggestion appreciated -- even the strangest, ugliest, most horrific of hacks. Thanks.


cheers,

[0] https://docs.python.org/3/c-api/buffer.html
[2] https://github.com/python/typing/issues/593

_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: guido@python.org
--
--Guido (mobile)