How do I annotate a bytes-like object or a Buffer?
There is no interface for the buffer protocol but I wish to accept all buffers in a function of mine.
I don't mind if it's only mypy-specific.
How do I annotate a bytes-like object or a Buffer?
There is no interface for the buffer protocol but I wish to accept all buffers in a function of mine.
I don't mind if it's only mypy-specific.
Currently (as of Python 3.6) the "Buffer Protocol" is a C API thing only - you can't even talk about it in regular Python code.
cf: Add typing.py class describing a PEP 3118 buffer object
I would use Any
for now.
Starting with Python 3.12, collections.abc.Buffer can be used like so:
from collections.abc import Buffer
def foo(buffer: Buffer):
pass