Repository navigation
fix(corekit): pack a bytearray into an s or p field on PyPy too (#2004) - #2007
Merged
Merged
Conversation
PyPy's struct.pack takes bytes alone for the s and p formats, where CPython also takes a bytearray, so Field.pack raised TypeError on PyPy for a bytearray value. Field.pack now hands struct.pack a bytes copy for those formats. CPython output is unchanged, and a memoryview, or a bytearray for the c format, stays refused as CPython refuses it.
Owner
Author
|
GOOD TO GO at
I ran all 22 |
Contributor
|
Coverage: 91.54% (unit tier, Python 3.15,
Per-file detail: the |
5 tasks done
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.
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
Field.packnow passes abytearraytostruct.packasbyteswhen the format ends insorp. PyPy refuses abytearraythere withTypeError: expected bytes, got bytearray object, and CPython accepts it. This is the onlystruct.packcall undercorekit/fields/, soBytesField,StringField, the address fields and every wrapper go through it.memoryview, and abytearrayforc, are left alone: CPython already refuses both, so converting them would accept something new.test_fields_bytearray_pack_2004_unit.pyuses astructstand-in that refuses abytearray, as PyPy does. It fails without the fix: 8 SUBFAILED on CPython, 12 on PyPy 8.0.1. Thetests/corekit/test_fields_*files and the IPv6 CALIPSO make test pass on both interpreters.Closes #2004