Repository navigation
py/objstr: Fix b"".hex() so it returns an empty str object. - #18808
Merged
Merged
Conversation
Closed
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18808 +/- ##
==========================================
- Coverage 98.42% 98.42% -0.01%
==========================================
Files 174 174
Lines 22331 22329 -2
==========================================
- Hits 21980 21978 -2
Misses 351 351 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Code size report: |
Contributor
Isn't it the other way round?
(Code seems correct, but PR / commit message is confusing.) |
dpgeorge
force-pushed
the
py-bytes-hex-empty-arg
branch
from
February 16, 2026 23:29
d8b11db to
be6de9e
Compare
Member
Author
You are right! Thanks for picking that up, I've now updated the commit message and this PR text. |
As of CPython 3.7 `bytes.fromhex()` skips all ASCII whitespace. And as of CPython 3.8 `bytes.hex()` supports the optional separator argument. So this test no longer needs a .exp file. Signed-off-by: Damien George <[email protected]>
This reduces code duplication, and may help reduce code size. Signed-off-by: Damien George <[email protected]>
As per CPython behaviour, `b"".hex()` should return an empty str object (not an empty bytes object). Fixes issue micropython#18807. Signed-off-by: Damien George <[email protected]>
dpgeorge
force-pushed
the
py-bytes-hex-empty-arg
branch
from
March 4, 2026 01:07
be6de9e to
06bfefe
Compare
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.
Summary
As per CPython behaviour,
b"".hex()should return an empty str object (not an empty bytes object).Fixes issue #18807.
I also took the opportunity to remove the .exp file for the corresponding test, because now that we use CPython 3.8 as the baseline for testing MicroPython matches CPython for this test file.
Testing
Tested locally on the unix port. Will also be tested by CI.
Trade-offs and Alternatives
I made a helper function
make_empty_str_of_type()to try and mitigate code size change, and reduce code duplication.