El sáb, 23 abr 2022 a las 10:26, Jelle Zijlstra (<jelle.zijlstra@gmail.com>) escribió:
It's been a longstanding problem in typeshed that we cannot fully represent the C buffer protocol in stubs, and we have to make do with annotations of `bytes` or unions of common buffer types. I just submitted PEP 688 to add a new `types.Buffer` type that will fix this problem.

A preview of the rendered PEP is available at https://pep-previews--2549.org.readthedocs.build/pep-0688/. The PR is at https://github.com/python/peps/pull/2549.

The PEP is now live at https://peps.python.org/pep-0688/
 

Summary:
* types.Buffer is added to CPython, using an isinstance hook to check for the presence of the buffer protocol.
* In stubs, types.Buffer can be used as a base class.
* Static type checkers should not need to special case the new class in any way.

Please let me know if you have any feedback.