Fold remaining custom stdlib *Buffer types into _typeshed. (#6082)

Add ctypes base type to WriteableBuffer.
Add a ReadOnlyBuffer type from fcntl.
Base ReadableBuffer on WriteableBuffer and ReadOnlyBuffer.
Use these types in fcntl and ctypes stubs.
This commit is contained in:
Vincent Pelletier
2021-09-28 16:15:26 +09:00
committed by GitHub
parent 328d09a9a5
commit 4c0dccac0f
3 changed files with 16 additions and 22 deletions

View File

@@ -3,6 +3,7 @@
# See the README.md file in this directory for more information.
import array
import ctypes
import mmap
import sys
from os import PathLike
@@ -167,8 +168,13 @@ class SupportsNoArgReadline(Protocol[_T_co]):
class SupportsWrite(Protocol[_T_contra]):
def write(self, __s: _T_contra) -> Any: ...
ReadableBuffer = Union[bytes, bytearray, memoryview, array.array[Any], mmap.mmap] # stable
WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap] # stable
ReadOnlyBuffer = bytes # stable
# Anything that implements the read-write buffer interface.
# The buffer interface is defined purely on the C level, so we cannot define a normal Protocol
# for it. Instead we have to list the most common stdlib buffer classes in a Union.
WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, ctypes._CData] # stable
# Same as _WriteableBuffer, but also includes read-only buffer types (like bytes).
ReadableBuffer = Union[ReadOnlyBuffer, WriteableBuffer] # stable
# stable
if sys.version_info >= (3, 10):