Skip to content

Fix tail(0) returning the whole sequence (#626) - #633

Open
az51826295-sys wants to merge 1 commit into
pytoolz:masterfrom
az51826295-sys:fix-tail-zero
Open

Fix tail(0) returning the whole sequence (#626)#633
az51826295-sys wants to merge 1 commit into
pytoolz:masterfrom
az51826295-sys:fix-tail-zero

Conversation

@az51826295-sys

Copy link
Copy Markdown

tail(0, seq) sliced seq[-0:], and since -0 == 0 in Python that returns the entire sequence instead of an empty one, as reported in #626.

This adds an explicit n <= 0 guard returning an empty slice of the same type (tuple for plain iterators), matching tail type-preserving behavior, plus regression cases in test_tail (str, tuple, list, iterator, negative n). Full test suite passes locally.

Disclosure: the initial fix was produced by an AI coding agent and then human-reviewed; tests verified locally.

Closes #626

tail(0, seq) sliced seq[-0:], and since -0 == 0 that returns the
entire sequence instead of an empty one. Add an explicit n <= 0
guard that returns an empty slice of the same type (tuple for plain
iterators), matching tail's type-preserving behavior.

Adds regression cases to test_tail covering str, tuple, list,
iterator inputs and a negative n.

Co-Authored-By: Rookery Alpha (AI agent, human-reviewed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tail(0, seq) returns the whole sequence instead of empty (and is inconsistent across iterable types)

1 participant