Skip to content

feat(client): add strip_empty option to get_game_data - #267

Merged
MarTrepodi merged 1 commit into
developfrom
feat/game-data-strip-empty
Nov 10, 2026
Merged

MarTrepodi merged 1 commit into
developfrom
feat/game-data-strip-empty

Conversation

@MarTrepodi

Copy link
Copy Markdown
Collaborator

Description

Adds a keyword-only strip_empty option to get_game_data() on both SwgohComlink and SwgohComlinkAsync. It defaults to False, so existing callers get the full response unchanged.

/data always returns every collection key and populates only the requested ones. Unrequested list collections come back as [] and unrequested single-object collections (guildBanner, socialStatus, …) as null. With strip_empty=True those keys are dropped.

 get_game_data(..., device_platform="Android", *, strip_empty=False)
   payload = _build_game_data_payload(...)
   game_data = _post("data", payload)
+  if strip_empty
+    drop keys whose value is None, [] or {}
+    (falsy scalars such as 0, False and "" are kept)
   return game_data

The filter is a staticmethod on SwgohComlinkBase (_strip_empty_collections), next to _build_game_data_payload, so both clients share it.

Related Issues

None.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactor (code change that neither fixes a bug nor adds a feature)
  • Performance improvement
  • Documentation
  • Tests
  • CI / build / dependencies

Checklist

  • This PR targets the develop branch (only release PRs target main)
  • My commits follow the Conventional Commits / Angular convention (feat:, fix:, refactor:, etc.) — they become the changelog
  • I have not edited CHANGELOG.md by hand (it is generated from commit messages)
  • I have added/updated docstrings with type hints for any new or changed public methods
  • I have updated the docs (README.md, docs/, examples/) if user-facing behavior changed
  • I have added unit tests that cover my changes (mocked, not requiring a live comlink service)
  • Tests pass (uv run pytest tests/)
  • Ruff linter and formatter pass (uv run ruff check src/ tests/ and uv run ruff format --check src/ tests/)
  • Type check passes (uv run ty check src/swgoh_comlink/)
  • I have not bundled unrelated changes in this PR

Testing

Unit tests (tests/unit/test_client_requests.py, run against both clients):

get_game_data(items="UNITS")                    -> every key returned
get_game_data(items="UNITS", strip_empty=False) -> every key returned
get_game_data(items="UNITS", strip_empty=True)  -> drops [], {} and None; keeps 0 and ""
strip_empty is KEYWORD_ONLY with default False

uv run pytest tests/: 2099 passed, 31 skipped.

Against a public Comlink release:

Request Without strip_empty With strip_empty=True
items=DataItems.UNITS 82 keys, 1 populated 1 key (units, 11,582 entries, identical)
items=DataItems.SKILL | DataItems.ABILITY (async) 82 keys ability, skill
request_segment=1 82 keys 22 keys, every one identical to the full response

The first live run kept 6 keys that held no data. They were single-object collections returned as null, which is why None counts as empty.

Docs: the README method table and both examples/*/get_game_data.py show the option. Both examples run cleanly.

Merge Danger

Door: two-way. The option is new, opt-in and keyword-only; reverting removes it without touching any other behaviour.

Blast Radius: minimal. The default path only adds one if after the response is decoded. Callers who opt in should index with .get(), because collections they did not request are no longer present as keys.

🤖 Generated with Claude Code

/data returns every collection key, populating only the requested ones:
unrequested list collections come back as [] and unrequested single-object
collections as null. The new keyword-only strip_empty flag drops those keys
so the response holds only the collections that came back with data.
Falsy scalars such as 0, False and "" are kept.

Defaults to False, so existing callers get the full response unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation code testing labels Nov 10, 2026
@MarTrepodi
MarTrepodi merged commit f2746ba into develop Nov 10, 2026
12 checks passed
@MarTrepodi
MarTrepodi deleted the feat/game-data-strip-empty branch November 10, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code documentation Improvements or additions to documentation testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant