Skip to content

refactor(helpers): narrow TB reward table ids to str in get_tb_mission_scores - #184

Merged
MarTrepodi merged 1 commit into
developfrom
fix/tb-reward-table-ids
Oct 13, 2026
Merged

MarTrepodi merged 1 commit into
developfrom
fix/tb-reward-table-ids

Conversation

@MarTrepodi

Copy link
Copy Markdown
Collaborator

Description

Unblocks #175 (ty 0.0.56 → 0.0.86), whose Type Check fails on:

error[invalid-argument-type]: Argument to function `sorted` is incorrect
  --> src/swgoh_comlink/helpers/_territory_battle.py:543:26
543 |     if missing := sorted(wanted - curves.keys()):
    |                          ^^^^^^^^^^^^^^^^^^^^^^ Argument type `Any | None` does not satisfy upper bound
    |                                                 `SupportsDunderLT[Any] | SupportsDunderGT[Any]`

The comprehension filtered on one .get() call but yielded a second, un-narrowed one:

-    wanted = {
-        zone.get("encounterRewardTableId")
+    wanted: set[str] = {
+        table_id
         for definition in definitions
         for _, zone in _mission_zones(definition)
-        if zone.get("encounterRewardTableId")
+        if (table_id := zone.get("encounterRewardTableId"))
     }

This is the same walrus idiom the scoring loop below it already uses (if not (table_id := zone.get(...))). Behavior is unchanged, and each zone's id is now looked up once.

Related Issues

Unblocks #175. Once this is in develop, @dependabot rebase on #175 should turn its Type Check green.

Type of Change

  • Refactor (code change that neither fixes a bug nor adds a feature)

Checklist

  • This PR targets the develop branch
  • My commits follow the Conventional Commits / Angular convention
  • I have not edited CHANGELOG.md by hand
  • Existing unit tests cover the changed path (TestGetTbMissionScores.test_invalid_input_raises, missing-table case (_TB_DEFS, _TB_TABLES[1:]))
  • Tests pass (uv run pytest tests/unit: 1511 passed)
  • Ruff linter and formatter pass on src/ and tests/
  • Type check passes, under both the locked and the incoming ty
  • I have not bundled unrelated changes in this PR

Testing

before after
uv run ty check src/swgoh_comlink/ (locked ty 0.0.56) ✔ ✔
uvx ty@0.0.86 check src/swgoh_comlink/ ✖ 1 diagnostic ✔
uv run pytest tests/unit 1511 passed 1511 passed

git merge-tree against #175's head merges cleanly.

Merge danger: two-way door. The blast radius is one internal set comprehension in get_tb_mission_scores, with no public API or output change.

🤖 Generated with Claude Code

…n_scores

The set comprehension filtered on one zone.get("encounterRewardTableId")
call but yielded a second, so its elements stayed typed Any | None. ty
0.0.86 (Dependabot PR #175) rejects sorting such a set. Bind the id with
a walrus in the filter, as the scoring loop below already does, and
annotate the set as set[str]. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the code label Oct 13, 2026
@MarTrepodi
MarTrepodi merged commit 7a20532 into develop Oct 13, 2026
16 checks passed
@MarTrepodi
MarTrepodi deleted the fix/tb-reward-table-ids branch October 13, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant