py/objstr: Fix b"".hex() so it returns an empty bytes object.#18808
Open
dpgeorge wants to merge 3 commits intomicropython:masterfrom
Open
py/objstr: Fix b"".hex() so it returns an empty bytes object.#18808dpgeorge wants to merge 3 commits intomicropython:masterfrom
dpgeorge wants to merge 3 commits intomicropython:masterfrom
Conversation
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 <damien@micropython.org>
This reduces code duplication, and may help reduce code size. Signed-off-by: Damien George <damien@micropython.org>
Fixes issue micropython#18807. Signed-off-by: Damien George <damien@micropython.org>
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 22333 22331 -2
==========================================
- Hits 21982 21980 -2
Misses 351 351 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Code size report: |
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 bytes object (not an empty str 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.