From 337051501ba4b39d47c8f2133c8aa202f4985fbe Mon Sep 17 00:00:00 2001 From: Lawrence <32899150+lawrence-law@users.noreply.github.com> Date: Fri, 6 Mar 2020 22:51:37 +1100 Subject: [PATCH] Update imghdr's what() to broadly accept readable binaries instead of BinaryIO (#3811) * Run isort over imghdr.pyi --- stdlib/2and3/imghdr.pyi | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/stdlib/2and3/imghdr.pyi b/stdlib/2and3/imghdr.pyi index 1ea55a7e7..290629829 100644 --- a/stdlib/2and3/imghdr.pyi +++ b/stdlib/2and3/imghdr.pyi @@ -1,16 +1,21 @@ -from typing import overload, Union, Text, BinaryIO, Optional, Any, List, Callable -import sys import os +import sys +from typing import Any, BinaryIO, Callable, List, Optional, Protocol, Text, Union, overload + +class _ReadableBinary(Protocol): + def tell(self) -> int: ... + def read(self, size: int) -> bytes: ... + def seek(self, offset: int) -> Any: ... if sys.version_info >= (3, 6): - _File = Union[Text, os.PathLike[Text], BinaryIO] + _File = Union[Text, os.PathLike[Text], _ReadableBinary] else: - _File = Union[Text, BinaryIO] + _File = Union[Text, _ReadableBinary] @overload def what(file: _File, h: None = ...) -> Optional[str]: ... @overload def what(file: Any, h: bytes) -> Optional[str]: ... -tests: List[Callable[[bytes, BinaryIO], Optional[str]]] +tests: List[Callable[[bytes, Optional[BinaryIO]], Optional[str]]]