From a0477b8aa421e8be445a724b2046bd5cb28f1acd Mon Sep 17 00:00:00 2001 From: q0w <43147888+q0w@users.noreply.github.com> Date: Wed, 10 Nov 2021 13:07:06 +0300 Subject: [PATCH] Replace BinaryIO with IO[bytes] --- aiodocker/images.py | 10 +++++----- aiodocker/utils.py | 16 +++------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/aiodocker/images.py b/aiodocker/images.py index c8e309fe..a15877e9 100644 --- a/aiodocker/images.py +++ b/aiodocker/images.py @@ -2,9 +2,9 @@ import json import warnings from typing import ( + IO, Any, AsyncIterator, - BinaryIO, Dict, List, Mapping, @@ -230,7 +230,7 @@ async def delete( ) @staticmethod - async def _stream(fileobj: BinaryIO) -> AsyncIterator[bytes]: + async def _stream(fileobj: IO[bytes]) -> AsyncIterator[bytes]: chunk = fileobj.read(io.DEFAULT_BUFFER_SIZE) while chunk: yield chunk @@ -241,7 +241,7 @@ async def build( self, *, remote: str = None, - fileobj: BinaryIO = None, + fileobj: IO[bytes] = None, path_dockerfile: str = None, tag: str = None, quiet: bool = False, @@ -261,7 +261,7 @@ def build( self, *, remote: str = None, - fileobj: BinaryIO = None, + fileobj: IO[bytes] = None, path_dockerfile: str = None, tag: str = None, quiet: bool = False, @@ -280,7 +280,7 @@ def build( # noqa: F811 self, *, remote: str = None, - fileobj: BinaryIO = None, + fileobj: IO[bytes] = None, path_dockerfile: str = None, tag: str = None, quiet: bool = False, diff --git a/aiodocker/utils.py b/aiodocker/utils.py index 45c188a5..a63c03c0 100644 --- a/aiodocker/utils.py +++ b/aiodocker/utils.py @@ -6,17 +6,7 @@ import tarfile import tempfile from io import BytesIO -from typing import ( - IO, - Any, - BinaryIO, - Iterable, - Mapping, - MutableMapping, - Optional, - Tuple, - Union, -) +from typing import IO, Any, Iterable, Mapping, MutableMapping, Optional, Tuple, Union async def parse_result(response, response_type=None, *, encoding="utf-8"): @@ -227,12 +217,12 @@ def clean_filters(filters: Mapping = None) -> str: return json.dumps(filters) -def mktar_from_dockerfile(fileobject: BinaryIO) -> IO: +def mktar_from_dockerfile(fileobject: Union[BytesIO, IO[bytes]]) -> IO[bytes]: """ Create a zipped tar archive from a Dockerfile **Remember to close the file object** Args: - fileobj: a Dockerfile + fileobject: a Dockerfile Returns: a NamedTemporaryFile() object """