fix: accept memoryview in decode and decode_lazy - #160
Open
nikolauspschuetz wants to merge 1 commit into
Open
Conversation
rlp.decode rejected memoryview objects (is_bytes only accepts bytes and bytearray), and rlp.decode_lazy raised a TypeError because the lazy codec concatenates slices of the input (memoryview does not support +). Normalize a memoryview input to bytes at the top of both entry points, mirroring the existing bytearray handling, so memoryview is a first-class input like bytearray. Closes ApeWorX#115
nikolauspschuetz
marked this pull request as ready for review
July 22, 2026 06:22
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 #115.
rlp.decoderejectedmemoryviewobjects —is_bytes(frometh_utils) only acceptsbytes/bytearray, sorlp.decode(memoryview(encoded))raisedDecodingError: Can only decode RLP bytes, got type memoryview.Simply widening the type check is not enough in the pure-Python backend: the codec concatenates slices of the input (
prefix + item,rlp[i:i+1] + len_prefix), andmemoryviewdoes not support+, sodecode_lazy(memoryview(...))raisedTypeError: unsupported operand type(s) for +: 'memoryview' and 'memoryview'.Fix: normalize a
memoryviewinput tobytesat the top of bothdecodeanddecode_lazy, mirroring the existingbytearrayhandling. This makesmemoryviewa first-class input likebytearray(which already worked in both paths), works for both the pure-Python andrusty_rlpbackends, and round-trips for nested lists and with a sedes.Tests: added
tests/core/test_memoryview.py, mirroringtest_bytearray.py(coversdecode,decode_lazy, and a nested list). All three fail onmainand pass with this change.