Skip to content

Fixed slice filter adding fill_with to every slice when evenly divisible#2170

Closed
bibekmhj wants to merge 1 commit into
pallets:mainfrom
bibekmhj:fix/2118-slice-fill-evenly-divisible
Closed

Fixed slice filter adding fill_with to every slice when evenly divisible#2170
bibekmhj wants to merge 1 commit into
pallets:mainfrom
bibekmhj:fix/2118-slice-fill-evenly-divisible

Conversation

@bibekmhj

Copy link
Copy Markdown

Fixes #2118.

When the iterable length is evenly divisible by slices, slices_with_extra works out to 0, so the condition slice_number >= slices_with_extra is true for every iteration and fill_with gets appended to every slice. [1,2,3,4]|slice(4, 'foo') ends up as [[1,'foo'], [2,'foo'], [3,'foo'], [4,'foo']] instead of [[1], [2], [3], [4]].

Gating on slices_with_extra being non-zero fixes it. Uneven splits behave the same as before. Regression test added next to test_slice.

@davidism davidism closed this May 14, 2026
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.

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

2 participants