Repository navigation
fix(cache): preserve LRUDict.get defaults and LRU order - #8683
leandrodamascena merged 2 commits into
Conversation
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @Vl4dC, and welcome. Confirmed both halves on develop: a missing key with a truthy default raised KeyError, and a falsy cached value lost its recency and got evicted right after being read. key in self is the right check, and the docstring fix is welcome too. Our current callers don't hit either case, but the contract was wrong and your tests pin it. Approving, this goes out in 3.39.0, no rebase needed, and you'll be credited in the release notes.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8683 +/- ##
========================================
Coverage 96.99% 96.99%
========================================
Files 321 321
Lines 16332 16332
Branches 1473 1473
========================================
Hits 15841 15841
Misses 350 350
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |
|
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |



Issue number: closes #8682
Summary
Changes
LRUDictrecency. This preservesgetdefaults for missing keys and updates recency for cached falsey values.User experience
LRUDict.get("missing", "fallback")now returns"fallback"instead of raisingKeyError. Reading a cachedFalse,0,None, or empty string now protects that entry from being evicted as the least recently used item. Existing callers using truthy cached values retain their behavior.Verification
uv run --locked --no-default-groups --with pytest --with ruff --python 3.12 pytest tests/unit/test_lru_cache.py -q— 11 passed, 1 pre-existing skip.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.