Repository navigation
Encode bytes subclasses with a custom repr like plain bytes - #2859
Merged
Merged
Conversation
The bytes encoder sliced repr(o)[2:-1] to drop the b prefix and quotes, which assumes the repr of plain bytes. numpy.bytes_ under NumPy 2 has the repr np.bytes_(b'...'), so it was recorded as .bytes_(b'...' instead of its content. Use bytes.__repr__ so subclasses are encoded like bytes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR overviewNo security issues were found in this pull request. Reviews
|
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
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.
Closes #2858
The bytes encoder returns repr(o)[2:-1] to strip the b prefix and the quotes, which assumes the repr of plain bytes. Under NumPy 2 the repr of numpy.bytes_ is np.bytes_(b'hello'), so a numpy.bytes_ attribute (for example an element of an array with a bytes dtype) was recorded as a truncated repr instead of hello. Any bytes subclass that overrides its repr was affected the same way.
Changes:
Disclosure: found, reproduced and the draft fix tested locally with the help of an AI coding agent (Claude Code); reviewed before filing.