Fix slice filter appending fill_with when items divide evenly#2166
Closed
kimjune01 wants to merge 2 commits into
Closed
Fix slice filter appending fill_with when items divide evenly#2166kimjune01 wants to merge 2 commits into
kimjune01 wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2118.
When
len(seq) % slices == 0,slices_with_extrais 0, so the guardslice_number >= slices_with_extrais always true. Every slice gets aspurious
fill_withvalue appended even though no padding is needed.Fix: add a truthiness check —
slices_with_extra and slice_number >= slices_with_extra.