fix: guard against None rating objects in pitcher sorting functions (#13) #50
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-reviewing
ai-working
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
tech-debt
todo
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#50
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-database#13"
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?
Summary
Noneguards inget_total_opsinsidesort_pitchers()(line ~600) and the innersort_starters()closure (line ~679)PitchingCardRatings.get_or_none()returnsNonefor either vs-L or vs-R rating, the function now returnsfloat("inf")instead of raisingAttributeErroron.obp/.slgaccessFiles Changed
app/routers_v2/teams.pyTest Results
No test suite in this repo. Changes verified by code review — the fix mirrors the pattern already used in the DH-finding path (
try/except AttributeError), but uses an explicitNonecheck which is cleaner for this use case.Closes #13
Add None checks for vlval/vrval in get_total_ops inside sort_pitchers() and sort_starters(). Returns float("inf") when ratings are missing so pitchers without ratings sort to the end rather than raising AttributeError. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>AI Code Review
Files Reviewed
app/routers_v2/teams.py(modified)Findings
Correctness
get_total_opsinner functions — insort_pitchers()(~line 593) and thesort_starters()closure (~line 670) — now correctly guard againstNonebefore accessing.obp/.slg.float("inf")is the right sentinel:sort_values(by="total_ops")sorts ascending (lower OPS = better pitcher), soinfcorrectly pushes pitchers with missing ratings to the end rather than crashing with a 500.Security
Style & Conventions
Nonecheck is cleaner thantry/except AttributeErrorfor a function with a well-definedNone-or-object return contract likeget_or_none(). The PR author notes the existing DH path usestry/except— this slight inconsistency is acceptable since the explicit check is the more Pythonic approach here.Suggestions
# TODO: should this be max??comment at line ~605 is unrelated to this PR but worth addressing in a follow-up — the twoget_total_opsimplementations are now nearly identical and could be consolidated into a shared helper to reduce duplication.Verdict: APPROVED
Minimal, focused fix. Both affected call sites are patched, the sentinel value is semantically correct, and the code follows project conventions. ✅
Automated review by Claude PR Reviewer (posted as COMMENT — Gitea prevents self-approval)
8d1751c061to0948db0b49