mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
Suggestion: SliceableBuffer type alias (#9115)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
@@ -236,6 +236,29 @@ else:
|
||||
ReadableBuffer: TypeAlias = ReadOnlyBuffer | WriteableBuffer # stable
|
||||
_BufferWithLen: TypeAlias = ReadableBuffer # not stable # noqa: Y047
|
||||
|
||||
# Anything that implements the read-write buffer interface, and can be sliced/indexed.
|
||||
SliceableBuffer: TypeAlias = bytes | bytearray | memoryview | array.array[Any] | mmap.mmap
|
||||
IndexableBuffer: TypeAlias = bytes | bytearray | memoryview | array.array[Any] | mmap.mmap
|
||||
# https://github.com/python/typeshed/pull/9115#issuecomment-1304905864
|
||||
# Post PEP 688, they should be rewritten as such:
|
||||
# from collections.abc import Sequence
|
||||
# from typing import Sized, overload
|
||||
# class SliceableBuffer(Protocol):
|
||||
# def __buffer__(self, __flags: int) -> memoryview: ...
|
||||
# def __getitem__(self, __slice: slice) -> Sequence[int]: ...
|
||||
# class IndexableBuffer(Protocol):
|
||||
# def __buffer__(self, __flags: int) -> memoryview: ...
|
||||
# def __getitem__(self, __i: int) -> int: ...
|
||||
# class SupportsGetItemBuffer(SliceableBuffer, IndexableBuffer, Protocol):
|
||||
# def __buffer__(self, __flags: int) -> memoryview: ...
|
||||
# def __contains__(self, __x: Any) -> bool: ...
|
||||
# @overload
|
||||
# def __getitem__(self, __slice: slice) -> Sequence[int]: ...
|
||||
# @overload
|
||||
# def __getitem__(self, __i: int) -> int: ...
|
||||
# class SizedBuffer(Sized, Protocol): # instead of _BufferWithLen
|
||||
# def __buffer__(self, __flags: int) -> memoryview: ...
|
||||
|
||||
ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType]
|
||||
OptExcInfo: TypeAlias = Union[ExcInfo, tuple[None, None, None]]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user