Am 19.05.20 um 16:34 schrieb Guido van Rossum:
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?
The lack of a buffer protocol is something that I came across multiple times now while reviewing typeshed PRs, although I haven't worked with the buffer protocol myself yet. But it seems to be a common problem that we can't solve on the typeshed level. The best we could do is provide an alias for Union[bytes, bytearray, memoryview, array.array] that we could use whenever the stdlib accepts buffer protocol object. But in my opinion it would be better to do it "right" and provide a buffer protocol type that could be used for such third-party classes as well. Of course it's possible to cast or # type: ignore whenever passing such an object, but that's hardly convenient and defeats the type checks. The caller must be sure that e.g. fcntl.ioctl() supports the buffer interface and can't rely on type checks. - Sebastian