Repository navigation
fix(examples): skip comment lines when decoding language bundles - #259
Merged
Merged
Conversation
Current localization bundles contain '#' comment lines with no '|'
delimiter (e.g. '# Start Category: ...', a bare '#'). The Sync and Async
get_language_bundle examples unpacked line.split("|") into two names and
raised ValueError on the first of them.
Both examples now skip blank and '#' lines and split on the first '|'
only, matching the library parser. Their docstrings point to
get_localization_dictionary / async_get_localization_dictionary as the
supported way to build the lookup. Both print the lookup size, and the
Async main() returns the dict so the script exposes der_str_lookup like
the Sync one.
Adds tests/examples/test_get_language_bundle.py, which runs each example
against a patched client serving a bundle with comment lines, blank lines
and a value containing '|'.
Closes #248
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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 #248
What changed
Current localization bundles contain
#comment lines with no|delimiter, such as# Start Category: Star_Wars_Strategy_RPG,# End Category: ... (65847 strings)and a bare#.examples/Sync/get_language_bundle.pyandexamples/Async/get_language_bundle.pyrankey, value = line.split("|")on every line, so both raisedValueErroron the first comment line.#lines and split on the first|only (line.partition("|"), skipping lines with no separator). This matches the library parser inhelpers/_game_data.py.get_localization_dictionary/async_get_localization_dictionaryas the supported way to build the lookup. The examples still teach the manual decode.main()now returns the dict, and the module assigns it toder_str_lookupthe same way the Sync script does. The Async example was already correct async code (async with/await); nothing else changed there.tests/examples/test_get_language_bundle.pyruns each example against a patched client that serves a bundle with comment lines, a blank line and a value containing|. Both cases fail ondevelopwith the unpackValueErrorand pass with this change.No library code changed.
Verification
uv run ruff check src/ tests/ examples/ parity/: passeduv run ruff format --check src/ tests/ examples/ parity/: passeduv run ty check src/swgoh_comlink/: passeduv run pytest tests/unit -q: 1622 passeduv run pytest tests/examples -q: 17 passed (2 new)http://comlink.lab:3200without HMAC, from temporary copies with the URL swapped: both the Sync and the Async example exit cleanly and reportBuilt a lookup of 72275 German strings(72,358 lines minus 83 comment lines). The Sync example's dict is identical toget_localization_dictionary(..., language="ger_de")from the same server.🤖 Generated with Claude Code