mpy-cross: Fix output to stdout on Windows. #17879
Open
+26
−0
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.
Summary
Set stdout to binary mode on Windows to avoid corruption of MPY output.
By default, Windows uses text mode for stdout which will convert any newline byte (\n) to a carriage return + newline (\r\n) pair. This can corrupt the MPY output if the MPY contains any 0x0A byte.
Testing
I didn't see a way to test this using our existing test framework. But I have made a test in the python-mpy-cross project I maintain.
Failing test before the fix: https://github.com/pybricks/python-mpy-cross/actions/runs/16865780805/job/47772458449#step:4:538
Passing test after the fix: https://github.com/pybricks/python-mpy-cross/actions/runs/16866365087/job/47773824320#step:4:863
Test source: https://github.com/pybricks/python-mpy-cross/blob/f376b412573a0c8c825abc300c5e36a716a85f98/tests/test_mpy_cross.py#L40-L50