Skip to content

Commit 0bd7a57

Browse files
authored
TYP: tighten IO Protocols (#326)
1 parent 8429b2d commit 0bd7a57

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

pandas-stubs/_typing.pyi

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,32 @@ DtypeObj = Union[np.dtype[np.generic], ExtensionDtype]
6464
AnyStr_cov = TypeVar("AnyStr_cov", str, bytes, covariant=True)
6565
AnyStr_con = TypeVar("AnyStr_con", str, bytes, contravariant=True)
6666

67-
class BaseBuffer(Protocol): ...
68-
class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]): ...
69-
class WriteBuffer(BaseBuffer, Protocol[AnyStr_cov]): ...
67+
class BaseBuffer(Protocol):
68+
@property
69+
def mode(self) -> str: ...
70+
def seek(self, __offset: int, __whence: int = ...) -> int: ...
71+
def seekable(self) -> bool: ...
72+
def tell(self) -> int: ...
73+
74+
class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]):
75+
def read(self, __n: int = ...) -> AnyStr_cov: ...
76+
77+
class WriteBuffer(BaseBuffer, Protocol[AnyStr_con]):
78+
def write(self, __b: AnyStr_con) -> Any: ...
79+
def flush(self) -> Any: ...
7080

7181
class ReadPickleBuffer(ReadBuffer[bytes], Protocol):
72-
def readline(self, size: int | None = ...) -> bytes: ...
82+
def readline(self) -> bytes: ...
7383

7484
class ReadCsvBuffer(ReadBuffer[AnyStr_cov], Protocol[AnyStr_cov]):
7585
def __iter__(self) -> Iterator[AnyStr_cov]: ...
86+
def fileno(self) -> int: ...
7687
def readline(self) -> AnyStr_cov: ...
7788
@property
7889
def closed(self) -> bool: ...
7990

8091
class WriteExcelBuffer(WriteBuffer[bytes], Protocol):
81-
def truncate(self, size: Union[int, None] = ...) -> int: ...
92+
def truncate(self, size: int | None = ...) -> int: ...
8293

8394
FilePath = Union[str, PathLike[str]]
8495
FilePathOrBuffer = Union[

0 commit comments

Comments
 (0)