array: stub improvements (#7966)

- TypeVar changes from https://github.com/microsoft/pyright/issues/3501
- Fix pos-only param
- Use protocols instead of IO classes
This commit is contained in:
Jelle Zijlstra
2022-05-26 23:33:24 -07:00
committed by GitHub
parent 789c12ad90
commit 7d34d75582

View File

@@ -1,9 +1,9 @@
import sys
from _typeshed import Self
from _typeshed import ReadableBuffer, Self, SupportsRead, SupportsWrite
from collections.abc import Iterable
# pytype crashes if array inherits from collections.abc.MutableSequence instead of typing.MutableSequence
from typing import Any, BinaryIO, Generic, MutableSequence, TypeVar, overload # noqa: Y027
from typing import Any, Generic, MutableSequence, TypeVar, overload # noqa: Y027
from typing_extensions import Literal, SupportsIndex, TypeAlias
_IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]
@@ -21,20 +21,22 @@ class array(MutableSequence[_T], Generic[_T]):
@property
def itemsize(self) -> int: ...
@overload
def __init__(self: array[int], __typecode: _IntTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
def __init__(self: array[int], __typecode: _IntTypeCode, __initializer: bytes | Iterable[int] = ...) -> None: ...
@overload
def __init__(self: array[float], __typecode: _FloatTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
def __init__(self: array[float], __typecode: _FloatTypeCode, __initializer: bytes | Iterable[float] = ...) -> None: ...
@overload
def __init__(self: array[str], __typecode: _UnicodeTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
def __init__(self: array[str], __typecode: _UnicodeTypeCode, __initializer: bytes | Iterable[str] = ...) -> None: ...
@overload
def __init__(self, typecode: str, __initializer: bytes | Iterable[_T] = ...) -> None: ...
def __init__(self, __typecode: str, __initializer: Iterable[_T]) -> None: ...
@overload
def __init__(self, __typecode: str, __initializer: bytes = ...) -> None: ...
def append(self, __v: _T) -> None: ...
def buffer_info(self) -> tuple[int, int]: ...
def byteswap(self) -> None: ...
def count(self, __v: _T) -> int: ...
def extend(self, __bb: Iterable[_T]) -> None: ...
def frombytes(self, __buffer: bytes) -> None: ...
def fromfile(self, __f: BinaryIO, __n: int) -> None: ...
def frombytes(self, __buffer: ReadableBuffer) -> None: ...
def fromfile(self, __f: SupportsRead[bytes], __n: int) -> None: ...
def fromlist(self, __list: list[_T]) -> None: ...
def fromunicode(self, __ustr: str) -> None: ...
if sys.version_info >= (3, 10):
@@ -47,7 +49,7 @@ class array(MutableSequence[_T], Generic[_T]):
def remove(self, __v: _T) -> None: ...
def reverse(self) -> None: ...
def tobytes(self) -> bytes: ...
def tofile(self, __f: BinaryIO) -> None: ...
def tofile(self, __f: SupportsWrite[bytes]) -> None: ...
def tolist(self) -> list[_T]: ...
def tounicode(self) -> str: ...
if sys.version_info < (3, 9):