refactor(rlp): tighten encode/decode, unify length-prefix logic, lift docs#766
Merged
tcoratger merged 5 commits intoMay 24, 2026
Merged
Conversation
… docs Collapses encode_bytes + encode_list + encode_length into one shared length-prefix helper parameterised by base, and folds the four decode branches (short/long string, short/long list) into a single length helper with shared range parsing. Removes a defensive bounds check in the decode dispatcher that is unreachable from both call paths. Rewrites all docstrings and inline comments to match the bitfields module style: one sentence per line, no backticks, role-based prose, Phase N labels with concrete hex walkthroughs at every algorithm step. Adds tests for three previously uncovered error paths (leading-zero length bytes for long strings and long lists, inner item overshooting parent list boundary). RLP module now at 100% line and branch coverage. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the inlined hex literals with three Final-typed module constants (STRING_BASE, LIST_BASE, SHORT_FORM_MAX) carrying friendly docstrings that explain the why behind each value. Anchors every pytest.raises match pattern with ^...$ against the full error message, replacing partial substring and .* patterns that could silently pass on regressions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ork-agnostic facade The architectural test test_subspecs_do_not_import_concrete_fork forbids subspec modules from importing under lean_spec.forks.lstar. The top-level lean_spec.forks package already re-exports Block, BlockBody, and AggregatedAttestations, so the fix is a one-line consolidation of the three import lines into one fork-agnostic import. No runtime behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Module-level constants get docstrings per the project code style. Each docstring explains the why behind the value (boundary role, short/long form switchover, range layout) instead of restating the value. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Result
Test plan
uv run pytest tests/lean_spec/types/test_rlp.py— 352 passeduv run pytest tests/lean_spec/test_cli.py tests/lean_spec/subspecs/networking/enr/test_enr.py— consumers still greenjust check— ruff, format, ty, codespell, mdformat all passsrc/lean_spec/types/rlp.py