Skip to content

Commit 3370515

Browse files
authored
Update imghdr's what() to broadly accept readable binaries instead of BinaryIO (#3811)
* Run isort over imghdr.pyi
1 parent 89afe1e commit 3370515

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

stdlib/2and3/imghdr.pyi

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
from typing import overload, Union, Text, BinaryIO, Optional, Any, List, Callable
2-
import sys
31
import os
2+
import sys
3+
from typing import Any, BinaryIO, Callable, List, Optional, Protocol, Text, Union, overload
4+
5+
class _ReadableBinary(Protocol):
6+
def tell(self) -> int: ...
7+
def read(self, size: int) -> bytes: ...
8+
def seek(self, offset: int) -> Any: ...
49

510

611
if sys.version_info >= (3, 6):
7-
_File = Union[Text, os.PathLike[Text], BinaryIO]
12+
_File = Union[Text, os.PathLike[Text], _ReadableBinary]
813
else:
9-
_File = Union[Text, BinaryIO]
14+
_File = Union[Text, _ReadableBinary]
1015

1116

1217
@overload
1318
def what(file: _File, h: None = ...) -> Optional[str]: ...
1419
@overload
1520
def what(file: Any, h: bytes) -> Optional[str]: ...
16-
tests: List[Callable[[bytes, BinaryIO], Optional[str]]]
21+
tests: List[Callable[[bytes, Optional[BinaryIO]], Optional[str]]]

0 commit comments

Comments
 (0)