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

Replace BinaryIO with IO[bytes] #644

merged 7 commits into from
May 20, 2024

Conversation

q0w
Copy link
Contributor

@q0w q0w commented Nov 10, 2021

What do these changes do?

Replace BinaryIO with IO[bytes]

So mktar_from_dockerfile should take fileobj as Union[BytesIO, IO[bytes]] (IO[bytes] for else case) and return IO[bytes] because there is not any case with returning IO[str]. Also docker.images.build should also take fileobj as IO[bytes]
There is also a discussion about typing.IO: python/typing#829, so protocols are useless due to the amount of use.

Are there changes in behavior for the user?

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the changes folder
    • name it <issue_id>.<type> for example (588.bug)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@asvetlov
Copy link
Member

From my understanding, python/typing#829 recommends using protocols for function arguments.
Would you modify the PR to follow this suggestion?

@@ -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.

aiodocker/images.py Outdated Show resolved Hide resolved
@@ -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
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.

Copy link
Member

@achimnol achimnol left a comment

Choose a reason for hiding this comment

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

We need to revisit the test suite (#849), so I'm going to merge this first and do follow-ups.

@achimnol achimnol merged commit d71ac9e into aio-libs:master May 20, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants