Skip to content

Conversation

@Faholan
Copy link

@Faholan Faholan commented Apr 27, 2021

Using a BytesIO or StringIO instance as a buffer to pass to a discord File is useful and perfectly correct.

I thus think that it would be fine to add it as a typehint.

However, I did not found a generic typehint for those two, if one exists it will of course be much better to add that one.

@ThatXliner
Copy link
Contributor

Wouldn't typing.IO work?

@Faholan
Copy link
Author

Faholan commented Jun 9, 2021

Wouldn't typing.IO work?

I checked, and neither BytesIO nor StringIO are subclasses of typing.IO

@ThatXliner
Copy link
Contributor

But it's type hints

@bryanforbes
Copy link
Owner

There's a few issues at play here:

  • The documentation states that if you're going to pass a file-like object, it should be opened in binary mode. I'm not sure if StringIO should work, even if it does.
  • The PR should probably change BinaryIO to io.BufferedIOBase, but even then it's not quite right since that's not a protocol and file-like objects won't match.
  • The io type hints don't define any protocols for these things, which means that it's not going to check the shape of the thing passed in, but the class inheritance if we use BytesIO and StringIO. I almost think we should make a protocol for this.

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