-
Notifications
You must be signed in to change notification settings - Fork 335
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
Clarify type buffer protocol type annotations & associated limits #1227
Comments
This probably applies to other classes and functions as well. I'll do a more thorough look through the code later. |
Yeap. Was struggling with this. Might as well make in |
I'd prefer to avoid using After reading up on the default linters used by IDEs, I think some of our initial assumptions were wrong. Past versions might not have supported How does the following plan look?
I'm not sure when or if the backport module will add support for buffer protocol typing. At the moment, it's a pure Python project with no C. However, their README seems encouraging:
The PEP for buffer protocol typing is already in the python/peps repo. |
Just a little note, consider creating an alias for this complex types like:
And then using |
That was mentioned in the OP:
Since @einarf mentioned in discord discussion that there were more places than just this module that may be affected, is there an unexpected place to put this? Or is |
Should be fine |
Enhancement request:
What should be added/changed?
Einarf added support for arbitrary buffer protocol implementations as arguments to
arcade.gl.Texture.write
in #703.Everything works as described when executing. However, PyCharm's linter reports passing a
memoryview
instance towrite
as an incorrect type.There is currently no type hinting support for arbitrary buffer protocol implementations, but there is a promising recent PEP.
In the meantime, we can change
write
's signature to support a reasonable range of valid buffer protocol objects in PyCharm.arcade/arcade/gl/texture.py
Line 643 in 225209a
Replacing the above signature with the following seems to make PyCharm's default linter behave better:
Alternatively, we could add our own Union alias variable and throw everything reasonable in there. We definitely can't use protocols since we have to support 3.7 and they were added in 3.8 : https://peps.python.org/pep-0544/
What would it help with?
tl;dr we'd get PyCharm compatibility, more readable code, and probably future-proofing
The PEP mentioned earlier appears to outline the following reasons for creating an explicit buffer protocol class:
bytes
might not stay compatible withmemoryview
andbytearray
The text was updated successfully, but these errors were encountered: