Skip to content

Fix slice filter appending fill_with when items divide evenly#2166

Closed
kimjune01 wants to merge 2 commits into
pallets:mainfrom
kimjune01:fix-slice-fill-even-divisible
Closed

Fix slice filter appending fill_with when items divide evenly#2166
kimjune01 wants to merge 2 commits into
pallets:mainfrom
kimjune01:fix-slice-fill-even-divisible

Conversation

@kimjune01

Copy link
Copy Markdown

Fixes #2118.

When len(seq) % slices == 0, slices_with_extra is 0, so the guard
slice_number >= slices_with_extra is always true. Every slice gets a
spurious fill_with value appended even though no padding is needed.

Fix: add a truthiness check — slices_with_extra and slice_number >= slices_with_extra.

June Kim and others added 2 commits May 9, 2026 03:09
When the iterable length is evenly divisible by the slice count,
`slices_with_extra` is 0 and the condition `slice_number >=
slices_with_extra` is always true, causing fill_with to be
appended to every slice even though no slice is shorter than
any other.

Add a guard so fill_with is only appended when there are
actually shorter slices that need padding.

Fixes pallets#2118.
@davidism davidism closed this May 9, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slice returns one extra item when slice count is a divisor of iterable length and fill_with not none

2 participants