take()/drop(): raise a clear ValueError for negative n#628
Open
rantkiglorelgmx-lab wants to merge 2 commits into
Open
take()/drop(): raise a clear ValueError for negative n#628rantkiglorelgmx-lab wants to merge 2 commits into
rantkiglorelgmx-lab wants to merge 2 commits into
Conversation
added 2 commits
July 3, 2026 21:11
(cherry picked from commit 043186544daf8eb3a64c9433c8d6655a79e2c5de) (cherry picked from commit 33bdf3a249f941ac6862dfd23d09422c3b6c5702)
(cherry picked from commit 0ec3a5780115e457565436ac0087204cbe255bd6) (cherry picked from commit 1653e2f7b8b6aadb6a76c7caa5ba0996d7a8a74a)
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
take(n, seq)anddrop(n, seq)already reject negativen(via the underlyingitertools.islice), but with an opaque message —ValueError: Stop argument for islice() must be None or an integer: 0 <= x <= sys.maxsize./ similar fordrop. This adds an explicit guard raising a clear, function-specific message instead:(and the equivalent for
drop).Backward compatibility
Add-only — negative
nalready raised before this change; only the message is clearer.n == 0andn >= 1behavior is completely unchanged (verified:take(0, seq) == [],drop(0, seq) == list(seq), unchanged for alln >= 1).Note
I noticed #627 already addresses
tail(n, seq)forn <= 0— that fix is out of scope here; this PR only coverstake/drop's negative-nerror message, which doesn't overlap with it.Verification
Both commits independently red-before-green verified (100% changed-line coverage, all changed-line mutants caught under AST-level mutation testing). Full suite green:
183 passed, 1 deselected.Co-authored by Claude (Anthropic) as part of an automated hardening pass; independently re-verified before submission.