[mypyc] Add bytearray support - #10891
Merged
Merged
Conversation
97littleleaf11
marked this pull request as ready for review
July 29, 2021 14:45
JukkaL
reviewed
Jul 30, 2021
| assert brr3 == b'\x00\x01\x02\x03\x04' | ||
| brr4 = bytearray('string', 'utf-8') | ||
| assert brr4 == bytearray(b'string') | ||
| assert brr4 == b'string' |
Collaborator
There was a problem hiding this comment.
Explicitly annotate the variables as bytes, since right now the inferred type will be bytearray, which doesn't have a mypyc primitive type, so it reverts back to object.
Also test calling a function that accepts bytes with an actual argument that is a bytearray object annotated with type Any, to check the runtime type checking from Any to bytes works if the runtime value is a bytearray .
JukkaL
approved these changes
Jul 30, 2021
JukkaL
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the updates! Looks good now.
sthagen
added a commit
to sthagen/python-mypy
that referenced
this pull request
Jul 30, 2021
[mypyc] Add bytearray support (python#10891)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
bytearrayis treated as a subtype of bytes by mypy, even though they behavior differently in some cases. We keep this design and check bytearray before calling corresponding cpython API.Test Plan
Adds tests for
bytearraycreation.