pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Fix stubs for buffer types

Open aatle opened this issue 7 months ago • 3 comments
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__() to Sound, BufferProxy, Mask, Color, PixelArray. Also add __release_buffer__() to first three.
  • Replace internal image._BufferLike with typing_extensions.Buffer. Replace Sound.__init__() Any and numpy.ndarray overloads with one typing_extensions.Buffer overload.
  • Minor change to type of BufferProxy.write() buffer argument

aatle avatar Apr 09 '25 01:04 aatle