Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace BinaryIO with IO[bytes] #644

Merged
merged 7 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions aiodocker/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import json
import warnings
from typing import (
TYPE_CHECKING,
Any,
AsyncIterator,
BinaryIO,
Dict,
List,
Mapping,
Expand All @@ -14,6 +14,10 @@
overload,
)


if TYPE_CHECKING:
from _typeshed import SupportsRead
achimnol marked this conversation as resolved.
Show resolved Hide resolved

from typing_extensions import Literal

from .jsonstream import json_stream_list, json_stream_stream
Expand Down Expand Up @@ -230,7 +234,7 @@ async def delete(
)

@staticmethod
async def _stream(fileobj: BinaryIO) -> AsyncIterator[bytes]:
async def _stream(fileobj: "SupportsRead[bytes]") -> AsyncIterator[bytes]:
chunk = fileobj.read(io.DEFAULT_BUFFER_SIZE)
while chunk:
yield chunk
Expand All @@ -241,7 +245,7 @@ async def build(
self,
*,
remote: str = None,
fileobj: BinaryIO = None,
fileobj: "SupportsRead[bytes]" = None,
path_dockerfile: str = None,
tag: str = None,
quiet: bool = False,
Expand All @@ -261,7 +265,7 @@ def build(
self,
*,
remote: str = None,
fileobj: BinaryIO = None,
fileobj: "SupportsRead[bytes]" = None,
path_dockerfile: str = None,
tag: str = None,
quiet: bool = False,
Expand All @@ -280,7 +284,7 @@ def build( # noqa: F811
self,
*,
remote: str = None,
fileobj: BinaryIO = None,
fileobj: "SupportsRead[bytes]" = None,
path_dockerfile: str = None,
tag: str = None,
quiet: bool = False,
Expand Down
16 changes: 3 additions & 13 deletions aiodocker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what to use here as Tarfile.gettarinfo expects fileobj as BytesIO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's keep BytesIO if there is no choice.

I can recommend making a PR for typeshed; they accept corrections easily and quickly if a patch is correct.

"""
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
"""
Expand Down