fix: IntervalDict.pop(key, None) raises KeyError instead of returning None#113
Closed
gaoflow wants to merge 1 commit into
Closed
fix: IntervalDict.pop(key, None) raises KeyError instead of returning None#113gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
… None `pop(key, default)` used `default is None` to detect whether a default was provided, so `pop(key, None)` was treated the same as `pop(key)` and raised KeyError for missing keys. Replace the `None` sentinel with a private `_MISSING` object so any explicitly supplied default — including `None` — is respected. Fixes behaviour to match Python's built-in `dict.pop(key, default)`: - `pop(key)` with no default → KeyError if missing (unchanged) - `pop(key, None)` → returns `None` for missing key (was: KeyError) - `pop(key, val)` → returns `val` for missing key (unchanged)
Owner
|
Thanks for proposing this "fix" (it wasn't an issue since the behaviour aligns with the documentation). Was there a human involved in the loop? Do you use this library? Your recent activity suggests (creating hundreds of PRs in dozens of unrelated projects) this was fully automatically generated by an AI. |
Author
|
Thanks for calling this out. You're right that I misread the documented contract here, so this PR should not be treated as a bug fix. There was human review in the loop, but the patch was AI-assisted and I do not use this library in production. I should have been more conservative before opening the PR. Closing this to avoid taking more maintainer time. |
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.
What
IntervalDict.pop(key, default)usesdefault is Noneto detect whether adefault argument was supplied, so passing
Noneexplicitly is indistinguishablefrom calling
pop(key)with no default:Python's built-in
dict.popalways returns the default when one is given,regardless of its value.
Fix
Replace the
Nonesentinel with a private_MISSING = object()sentinel sothat any explicitly supplied default — including
None— is honoured.Test
Added an assertion to
test_pop_missing_valuethatpop(key, None)returnsNonefor a missing key rather than raisingKeyError.This pull request was prepared with the assistance of AI, under my direction and review.