Fix stubs for buffer types#3398
Conversation
ankith26
left a comment
There was a problem hiding this comment.
This PR is failing stubtest, it is complaining that __buffer__ and __release_buffer__ are not actually present at runtime
|
Yes, I'll probably have to add a regex to |
|
It is probably dependent on the python version, I would suggest adding a python version check in the code instead of adding it to mypy allow list |
ankith26
left a comment
There was a problem hiding this comment.
I'm not exactly clear what is the logic behind some places having __release_buffer__ and some places not having it. In my understanding from the docs, __release_buffer__ is only needed when some cleanup must be done.
Can you please clarify, and also maybe document it in the code/stubs with comments
|
I didn't know why some had
I won't document this in the code nor in stubs with comments, it's not of this PR's concern to explain C code internal implementations. |
zoldalma999
left a comment
There was a problem hiding this comment.
Looks good except for one nitpick. Feel free to resolve it (or not) and merge afterwards.
Python 3.12 introduced the python-visible buffer protocol with
__buffer__and__release_buffer__. It also definedcollections.abc.Buffer.This PR allows static type checkers to recognize some pygame types as buffers, helpful for
Surfacebuffer operations with other libraries likenumpy.Stub changes:
__buffer__()toSound,BufferProxy,Mask,Color,PixelArray. Also add__release_buffer__()to first three.image._BufferLikewithtyping_extensions.Buffer. ReplaceSound.__init__()Anyandnumpy.ndarrayoverloads with onetyping_extensions.Bufferoverload.BufferProxy.write()buffer argument