Repository navigation
fix(corekit): refuse a non-bytes value for the c format on every engine (#2015) - #2018
Conversation
…ne (#2015) GraalPy's struct packs a bytearray for the c format, where CPython's raises struct.error, so Field.pack now refuses anything but bytes for c itself with StructError (a struct.error subclass). The test pins that error and adds a lenient struct stand-in that reproduces GraalPy's behaviour on CPython.
|
GOOD TO GO at A Sonnet cross-review checked every claim it set out to:
The behaviour has not been checked on GraalPy itself: the test stands in for GraalPy's |
|
Coverage: 91.55% (unit tier, Python 3.15,
Per-file detail: the |
|
cant we just convert like the line before? |
|
Yes. I'll change the fix so that a |
…g it (#2015) Field.pack now hands a bytearray for c over as bytes, as it already does for s and p, so it packs identically under CPython's struct (which refuses one) and GraalPy's (which takes one). The StructError refusal is dropped. A memoryview is still passed through unconverted. Tests pin the c packing under the real struct and a lenient stand-in.
|
GOOD TO GO at A Sonnet re-review confirmed:
GraalPy itself was not run. |
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
GraalPy's
structpacks abytearrayfor thecformat, but CPython's raisesstruct.error.Field.packalready converts abytearraytobytesforsandp(#2004); it now does the same forc, so abytearraypacks identically on every engine. Amemoryviewis not converted, because CPython refuses one forc,sandpalike; it is passed straight through tostruct. No library field usesc.What the tests check:
test_bytearray_for_the_c_format_packs_as_bytes: abytearray, or a subclass of one, packs the same asb'a', both under the realstructand under a stand-in that accepts buffers the way GraalPy's does. Withmain'sfield.py, it fails 4 subtests.test_memoryview_for_the_c_format_is_left_to_struct:Field.packhands thememoryviewtostructunchanged.GraalPy is not installed locally, so this was not run there. Only narrow selections were run, not
make test:test_fields_bytearray_pack_2004_unit.pyandtest_fields_field.pypass.Closes #2015