-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add bytearray.decode() for CPython compatibility #2896
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
CPython has a `decode()` method on `bytearray`. This adds that method using the code from `bytes.decode`. Test program: ```python byte_boi = bytes([0x6D, 0x65, 0x65, 0x70]) print(byte_boi) # b'meep' byte_boi_str = byte_boi.decode("utf-8") print(byte_boi_str) # meep byte_array_boi = bytearray(byte_boi) print(byte_array_boi) # bytearray(b'meep') byte_array_boi_str = byte_array_boi.decode("utf-8") print(byte_array_boi_str) # meep print(byte_array_boi_str == byte_boi_str) # True ```
4e47bf4
to
fe3e8ee
Compare
Does this unintentionally add it to For CPython:
|
Also note this, though I'm not sure whether it's relevant: #384 |
Ah it seems like it does add it to array, too. I can fix that if you want.
…On Fri, May 15, 2020, 12:00 PM Dan Halbert ***@***.***> wrote:
Also note this, though I'm not sure whether it's relevant: #384
<#384>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2896 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB5I444WAHHP6QYRT4XRDTRRWGNJANCNFSM4NBHYU4Q>
.
|
@tannewt made it where decode only applies to print(dir(array.array))
# ['__class__', '__name__', 'append', 'extend']
print(dir(bytearray))
# ['__class__', '__name__', 'append', 'decode', 'extend'] |
As I feared, giving bytearray a separate locals table pushed some of the smaller boards over capacity. :( |
I shrank the crickit build. Let's see if it works. |
Thanks, @dhalbert |
I'm pretty puzzled by this. I checked out the exact same commit locally (a3ca940), and my builds are about 500 bytes smaller, and they fit. I'm using the same EDIT: It was the original commit, not the merge commit. |
@tannewt it builds now; I think you already took a look so if it's easy for you to finish the review go ahead |
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.
Looks great! Thanks for doing this!
CPython has a
decode()
method onbytearray
. This adds that method using the code frombytes.decode
.Test program: