Summary
tail(n, seq) is implemented as seq[-n:] (with a deque fallback). For n == 0, seq[-0:] is seq[0:] — the entire sequence — so tail(0, seq) returns everything instead of the last zero elements. It is also inconsistent across input types: sliceable inputs return the whole sequence, while non-sliceable iterables hit the deque(seq, 0) fallback and correctly return empty.
Reproduction
from toolz import tail
print(tail(0, [10, 20, 30])) # [10, 20, 30] <- expected () / empty
print(tuple(tail(0, iter([10, 20, 30])))) # () (deque fallback: empty)
Expected
tail(0, seq) returns an empty result (the last zero elements), consistently for any iterable.
Actual
Returns the whole sequence for sliceable inputs and empty for non-sliceable ones — inconsistent, and wrong for n == 0.
Fix sketch
Special-case n <= 0 to return empty, or route through the deque path uniformly.
Environment
toolz 1.1.0 (master @ 568c2b8), Python 3.12.
Summary
tail(n, seq)is implemented asseq[-n:](with adequefallback). Forn == 0,seq[-0:]isseq[0:]— the entire sequence — sotail(0, seq)returns everything instead of the last zero elements. It is also inconsistent across input types: sliceable inputs return the whole sequence, while non-sliceable iterables hit thedeque(seq, 0)fallback and correctly return empty.Reproduction
Expected
tail(0, seq)returns an empty result (the last zero elements), consistently for any iterable.Actual
Returns the whole sequence for sliceable inputs and empty for non-sliceable ones — inconsistent, and wrong for
n == 0.Fix sketch
Special-case
n <= 0to return empty, or route through thedequepath uniformly.Environment
toolz 1.1.0 (master @ 568c2b8), Python 3.12.