fix: guard all .get(key, 0) patterns that can return None (7 files, 17 occurrences)#822
Merged
mvanhorn merged 2 commits intoJul 15, 2026
Merged
Conversation
… latin-1 encode crash
Contributor
Greptile SummaryThis PR makes nullable engagement and score fields safer to read. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "fix: guard all .get(key, 0) patterns tha..." | Re-trigger Greptile |
… TypeError on arithmetic/sort/sum/max
dict.get(key, default) only substitutes the default when the key is
absent. A key that exists with value None passes through, producing
None instead of the intended default. This causes TypeError in:
- arithmetic (reactions + comments)
- list.sort() with key function
- max() comparisons
- sum() over generator expressions
Fixes 17 occurrences across 8 files:
- github.py: item.get("comments", 0) used in reactions + comments
- briefing.py: f.get("engagement_score", 0) used in max()/sum()
- youtube_yt.py: .get("views", 0) inside sort key
- instagram.py: same sort-key pattern
- tiktok.py: same sort-key pattern
- hackernews.py: .get("points", 0) in sort key
- signals.py: .get("views", 0) in engagement floor check
- store.py: .get("engagement_score", 0) / .get("relevance_score", 0)
in store_sightings (same root cause as PR mvanhorn#796)
35a3a1b to
055f475
Compare
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.
Problem
dict.get(key, default)only substitutesdefaultwhen the key is absent. A key that exists with valueNonepasses straight through, so.get("views", 0)returnsNoneand operations crash withTypeError.Fix
Replace all 17 occurrences of
dict.get(key, 0)withdict.get(key) or 0where the dict value can beNone— same root cause and fix pattern as PR #796.Files changed (8 files, +17/−17)
lib/github.pyitem.get("comments", 0)inreactions + commentsarithmeticbriefing.pyf.get("engagement_score", 0)inmax()/sum()lib/youtube_yt.py.get("views", 0)inlist.sort(key=...)lib/instagram.pylib/tiktok.pylib/hackernews.py.get("points", 0)inlist.sort(key=...)lib/signals.py.get("views", 0)in engagement floor comparisonstore.pystore_sightingsboundary: engagement_score and relevance_scoreVerification
All tests pass: store, signals, briefing, youtube, tiktok, hackernews, instagram, cli, internals, render.