-
Notifications
You must be signed in to change notification settings - Fork 26
Support string input streams #22
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
Conversation
|
|
||
| _data_buffer = io.BytesIO() | ||
| _data_buffer.write(b"".join(data.split())) | ||
| _data_buffer = io.BytesIO() if isinstance(data, bytes) else io.StringIO() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method return type annotation needs to change to AnyStr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. The mypy tests are failing but I'm not sure why - I haven't used mypy previously. It looks like a false positive - maybe mypy is not able to handle the branching logic that handles bytes and str differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial problem is just that you need to add an import for AnyStr in the types imports at the top. I'm not sure if the other issues it's running into are just a side effect of missing that or not.
|
I have attempted to fix the mypy test but failed. Adding import of |
mattsb42-aws
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to hack on this a bit before we publish both to see if I can sort out the type annotations and because I have a feeling it might need a couple tweaks to correctly handle unicode in both Python 2 and 3. I want to expand the tests to figure out whether that is an issue, but I don't think it's useful to try and iterate over that through this PR.
I think this is gets us most of the way there, thanks!
Refs #21
Alters the
Base64IO.read()method to support string streams as well as bytes streams.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.