Fix: Serialize each object at its outermost layer only #131
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
Fix inconsistent Player serialization in team lists - objects now serialize at their outermost layer only
Problem
The
serialize()function mixed integers and full Player dicts in team lists:Expected:
Root Cause
When serializing a list, objects from later in the list were serialized WITHIN earlier objects.
Example: In player list
[P1, P2, P3, P4], P1 has{team: [P1, P3]}. When serializing P1's team, P3 would be fully serialized instead of using a hash value and letting P3 be serialized later in the outer list.Solution
Two-pass approach for lists:
outer layer will now use hash value.
Each object is fully serialized exactly once at its outermost layer.
Testing
Added 3 new tests in
tests/test_serialize.py:test_players_are_dicts: Players serialize as full dict objectstest_team_references_are_integers: Team lists contain only integerstest_no_circular_references: No circular references in serialized dataAll 24 tests pass (21 existing + 3 new)
Impact
🤖 Initially generated with Claude Code, edited & verified manually.