[alt] typing: accept buffers in IO.write (#9861)

Co-authored-by: JelleZijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Alex Waygood
2023-03-15 07:42:10 +00:00
committed by GitHub
parent b7d1079e86
commit 21d7f7153b
7 changed files with 68 additions and 12 deletions

View File

@@ -2,7 +2,7 @@ import collections # Needed by aliases like DefaultDict, see mypy issue 2986
import sys
import typing_extensions
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import IdentityFunction, Incomplete, SupportsKeysAndGetItem
from _typeshed import IdentityFunction, Incomplete, ReadableBuffer, SupportsKeysAndGetItem
from abc import ABCMeta, abstractmethod
from contextlib import AbstractAsyncContextManager, AbstractContextManager
from re import Match as Match, Pattern as Pattern
@@ -687,8 +687,22 @@ class IO(Iterator[AnyStr], Generic[AnyStr]):
@abstractmethod
def writable(self) -> bool: ...
@abstractmethod
@overload
def write(self: IO[str], __s: str) -> int: ...
@abstractmethod
@overload
def write(self: IO[bytes], __s: ReadableBuffer) -> int: ...
@abstractmethod
@overload
def write(self, __s: AnyStr) -> int: ...
@abstractmethod
@overload
def writelines(self: IO[str], __lines: Iterable[str]) -> None: ...
@abstractmethod
@overload
def writelines(self: IO[bytes], __lines: Iterable[ReadableBuffer]) -> None: ...
@abstractmethod
@overload
def writelines(self, __lines: Iterable[AnyStr]) -> None: ...
@abstractmethod
def __next__(self) -> AnyStr: ...