Skip to content

fix(filters): do not append fill_with when items divide evenly across slices#2154

Closed
justDance-everybody wants to merge 4 commits intopallets:mainfrom
justDance-everybody:clawoss/fix/slice-filter-fill-with-2118
Closed

fix(filters): do not append fill_with when items divide evenly across slices#2154
justDance-everybody wants to merge 4 commits intopallets:mainfrom
justDance-everybody:clawoss/fix/slice-filter-fill-with-2118

Conversation

@justDance-everybody
Copy link
Copy Markdown

@justDance-everybody justDance-everybody commented Apr 3, 2026

Fixes #2118 - see commit message for details

Copilot AI review requested due to automatic review settings April 3, 2026 06:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes slice filter behavior in Jinja2 so that fill_with is not appended when the input length divides evenly across the requested number of slices.

Changes:

  • Update sync_do_slice to only append fill_with when there is a remainder (slices_with_extra > 0) and the current slice is one of the shorter slices.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/jinja2/filters.py
Comment on lines +1092 to +1093
if (
fill_with is not None
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a regression test for the case where the input length divides evenly by the number of slices (so slices_with_extra == 0). With fill_with provided, this should not append any filler items (e.g., range(9)|slice(3, 'X') should yield [[0,1,2],[3,4,5],[6,7,8]]). This will ensure the bug fixed here doesn’t reappear, and should be covered in both sync and async filter tests if applicable.

Copilot uses AI. Check for mistakes.
@davidism davidism closed this Apr 3, 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

3 participants