-
-
Notifications
You must be signed in to change notification settings - Fork 176
Fix stubs for buffer types #3398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the PR 🎉
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
Surface
buffer operations with other libraries likenumpy
.Stub changes:
__buffer__()
toSound
,BufferProxy
,Mask
,Color
,PixelArray
. Also add__release_buffer__()
to first three.image._BufferLike
withtyping_extensions.Buffer
. ReplaceSound.__init__()
Any
andnumpy.ndarray
overloads with onetyping_extensions.Buffer
overload.BufferProxy.write()
buffer argument