-
-
Notifications
You must be signed in to change notification settings - Fork 107
Fix: allow foreach_get/set to accept Buffer types #260
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
Conversation
Thank you for tackling this issue.
|
We should also change |
11fdeb3
to
a11e9aa
Compare
Done! 👍
They don't have |
|
Unless |
Using Alternatively we can use |
This is what flake8-pyi recommands too. |
#161 includes a proposal to use the
...which I quoted in the OP. Am I misunderstanding when I take this to mean I can use types like |
E.g. in my case I have only Python 3.11 and PyRight is okay with using Python 3.12 syntax (PEP 695) in .pyi files but it will fail if I try to import something that's only available in Python 3.12 as it's still using Python 3.11 stub file for Btw, just noticed that from typing_extensions import Buffer
class ClassA:
def accept_buffer2(self, buffer: Buffer):
pass
a = ClassA()
from array import array
import numpy as np
array_buffer = array("l", [1, 2, 3, 4, 5])
np_buffer = np.array([1, 2, 3, 4, 5], dtype=np.int32)
print(memoryview(array_buffer))
print(memoryview(np_buffer))
a.accept_buffer2(array_buffer)
# Argument of type "NDArray[signedinteger[_32Bit]]" cannot be assigned to parameter "buffer" of type "Buffer" in function "accept_buffer2"
# "ndarray[Any, dtype[signedinteger[_32Bit]]]" is incompatible with protocol "Buffer"
# "__buffer__" is not present
a.accept_buffer2(np_buffer) |
You could but it would be less correct, also |
2678785
to
250f4c4
Compare
250f4c4
to
8fb4bc2
Compare
[4.7.0](https://github.com/python/typing_extensions/releases/tag/4.7.0) is the minimum version for Python 3.12 features; semantic versioning means the backwards-incompatible changes will only be made in the next major version (5.0.0).
Thank you @Road-hog123 |
As per #161:
collections.abc.Buffer
was added in Python 3.12 for typing classes that implement the buffer protocol—it is not possible to specify the contained type or mutability of the buffer.Fixes #257