pygame-ce
pygame-ce copied to clipboard
Fix stubs for buffer types
trafficstars
Python 3.12 introduced the python-visible buffer protocol with __buffer__ and __release_buffer__. It also defined collections.abc.Buffer.
This PR allows static type checkers to recognize some pygame types as buffers, helpful for Surface buffer operations with other libraries like numpy.
Stub changes:
- Add
__buffer__()toSound,BufferProxy,Mask,Color,PixelArray. Also add__release_buffer__()to first three. - Replace internal
image._BufferLikewithtyping_extensions.Buffer. ReplaceSound.__init__()Anyandnumpy.ndarrayoverloads with onetyping_extensions.Bufferoverload. - Minor change to type of
BufferProxy.write()buffer argument