feat: rarity ladder utility for safe next-rarity lookups (#59) #64
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-card-creation#64
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/59-feat-rarity-ladder-utility-for-safe-next-rarity-lo"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #59
Summary
Adds
RARITY_LADDER,rarity_is_downgrade(), andnext_rarity()torarity_thresholds.py.RARITY_LADDER— ordered list[5, 4, 3, 2, 1, 99](Common → Bronze → Silver → Gold → Diamond → HoF). Canonical ordering for all tier comparisons.next_rarity(current_id)— returns the next more-prestigious rarity ID, orNoneat HoF or for unknown IDs. Prevents the naiverarity_id + 1bug (100 for HoF, 0 for Diamond).rarity_is_downgrade(current_id, new_id)— returnsTrueifnew_idis less prestigious thancurrent_id. Used by the T4 rarity guard (card-creation#57).Files Changed
rarity_thresholds.py— +53 lines (ladder constant + two helper functions)Tests
No test suite in this repo. Logic verified by reading the implementation:
RARITY_LADDER.index()lookups handle all edge cases cleanly, andNoneis returned at both ends (HoF max, unknown ID).AI Code Review
Files Reviewed
rarity_thresholds.py(modified)Findings
Correctness
Merge conflict — PR is not mergeable.
RARITY_LADDERandrarity_is_downgradewere already added tomainas part of PR #63 (T4 rarity guard fix, commitaaa2eaa). The currentmainhas both at lines 149–168. This PR's branch was created before that merge, so it conflicts on those exact lines. Gitea confirms"mergeable": false. The branch needs to be rebased onto currentmain; after rebase, onlynext_raritywill be a new addition.After rebasing, the
RARITY_LADDERalready on main lacks thelist[int]type annotation — the PR's version (RARITY_LADDER: list[int] = [...]) is preferable and should be kept.rarity_is_downgradeunknown-new_rarity_idbehaviour not documented. The docstring says "Unknown IDs are treated as position 0 (worst), so an unknown current rarity will never trigger a downgrade guard." It omits what happens whennew_rarity_idis unknown (also returnsFalse). A one-sentence addition would close the gap (e.g. "An unknownnew_rarity_idalso returns False."). The behaviour itself is fine — it avoids false positives when the system produces an unexpected ID — but the omission makes the contract ambiguous.Security
Style & Conventions
next_raritydocstring with examples is clear and follows existing patterns.Suggestions
next_rarityis not yet called anywhere in the codebase. Correct for a utility being added ahead of use. No action needed.Verdict: REQUEST_CHANGES (posted as COMMENT — Gitea blocks self-review)
The
next_raritylogic is correct. Two issues block merge:main(introduced by PR #63) — rebase required.rarity_is_downgradedocstring should document the unknown-new_rarity_idreturn path.Automated review by Claude PR Reviewer
1d593a91a6tofeedfe951fAddressed review feedback:
Rebased onto current
main— resolved merge conflict with PR #63. After rebase, onlynext_rarityis a new addition;RARITY_LADDERandrarity_is_downgradealready existed onmain. Kept thelist[int]type annotation and expanded multi-line format forRARITY_LADDER(preferred over the untyped one-liner that landed via #63).Updated
rarity_is_downgradedocstring — added "An unknownnew_rarity_idalso returns False." to close the contract gap noted in the review.AI Code Review
Files Reviewed
rarity_thresholds.py(modified)Findings
Correctness
No issues found.
next_rarity()logic verified against all inputs:next_rarity(5)4(Bronze) ✓next_rarity(4)3(Silver) ✓next_rarity(3)2(Gold) ✓next_rarity(2)1(Diamond) ✓next_rarity(1)99(HoF) ✓next_rarity(99)len(RARITY_LADDER)-1None✓next_rarity(unknown)ValueErrorNone✓All docstring examples match implementation. The
rarity_is_downgradedocstring addition ("An unknown new_rarity_id also returns False") accurately describes the existing try/except behaviour.Prior review requested a rebase on top of PR #63 — confirmed resolved. Base is now
f3da587(PR #63 merge) andmergeable: true.Security
No issues found.
Style & Conventions
list[int]type annotation andint | Nonereturn type are consistent with existing annotations in the file.Suggestions
None.
Verdict: COMMENT
LGTM. Rebase resolved the prior conflict;
next_rarity()is correct and handles all edge cases. Ready to merge.Automated review by Claude PR Reviewer
Approved via pd-pr