From defa998ea0621ed1bd6ef75669d5c310c02d8c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 23 Sep 2022 21:41:46 -0400 Subject: [PATCH] TYP: tighten IO Protocols --- pandas-stubs/_typing.pyi | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 888141df1..e5e91133f 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -64,21 +64,32 @@ DtypeObj = Union[np.dtype[np.generic], ExtensionDtype] AnyStr_cov = TypeVar("AnyStr_cov", str, bytes, covariant=True) AnyStr_con = TypeVar("AnyStr_con", str, bytes, contravariant=True) -class BaseBuffer(Protocol): ... -class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]): ... -class WriteBuffer(BaseBuffer, Protocol[AnyStr_cov]): ... +class BaseBuffer(Protocol): + @property + def mode(self) -> str: ... + def seek(self, __offset: int, __whence: int = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + +class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]): + def read(self, __n: int = ...) -> AnyStr_cov: ... + +class WriteBuffer(BaseBuffer, Protocol[AnyStr_con]): + def write(self, __b: AnyStr_con) -> Any: ... + def flush(self) -> Any: ... class ReadPickleBuffer(ReadBuffer[bytes], Protocol): - def readline(self, size: int | None = ...) -> bytes: ... + def readline(self) -> bytes: ... class ReadCsvBuffer(ReadBuffer[AnyStr_cov], Protocol[AnyStr_cov]): def __iter__(self) -> Iterator[AnyStr_cov]: ... + def fileno(self) -> int: ... def readline(self) -> AnyStr_cov: ... @property def closed(self) -> bool: ... class WriteExcelBuffer(WriteBuffer[bytes], Protocol): - def truncate(self, size: Union[int, None] = ...) -> int: ... + def truncate(self, size: int | None = ...) -> int: ... FilePath = Union[str, PathLike[str]] FilePathOrBuffer = Union[