Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-145546: unittest.util: fixsorted_list_difference tail deduplication#145547

Open
stefanzetzsche wants to merge 8 commits intopython:mainfrom
stefanzetzsche:fix/unittest_util
Open

gh-145546: unittest.util: fixsorted_list_difference tail deduplication#145547
stefanzetzsche wants to merge 8 commits intopython:mainfrom
stefanzetzsche:fix/unittest_util

Conversation

@stefanzetzsche
Copy link

@stefanzetzschestefanzetzsche commentedMar 5, 2026
edited
Loading

Problem

sorted_list_difference doesn't deduplicate remaining elements when one list is exhausted. Theexcept IndexError fallback usesextend(expected[i:]) /extend(actual[j:]) which includes duplicates.

Reproducer

fromunittest.utilimportsorted_list_differenceprint(sorted_list_difference([], [0,0]))# ([], [0, 0]) — expected ([], [0])

Fix

Replace the raw extend(expected[i:]) / extend(actual[j:]) in the except IndexError fallback with a helper that removes consecutive duplicates. The helper only uses equality comparison (not hashing), matching the main loop's approach and preserving support for unhashable types like lists.

Tests

  • Tail deduplication with ints (empty list vs duplicates, mid-way exhaustion)
  • String inputs with duplicated tails
  • Unhashable types (lists of lists) to verify no hashing requirement is introduced

sorted_list_difference failed to deduplicate remaining elements when onelist was exhausted, causing duplicate values in the result.Fix uses dict.fromkeys() to deduplicate before extending.sim:https://taskei.amazon.dev/tasks/TODO
…icationExercise the except-IndexError path where one list is exhaustedand the remaining tail of the other list contains duplicates.These cases were previously untested and would have passed evenwithout the fix in the preceding commit.
@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

@stefanzetzschestefanzetzsche marked this pull request as ready for reviewMarch 5, 2026 14:14
Sphinx cannot resolve :func: references to unittest.util since it isnot part of the public documented API. Use double backticks instead.
dict.fromkeys requires hashable elements, which narrows the inputcontract. Replace with a simple consecutive-duplicate removal thatonly uses equality comparison, matching the main loop's approach.Add test cases for strings and unhashable types (lists).
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@aiskaiskaisk approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@stefanzetzsche@aisk

[8]ページ先頭

©2009-2026 Movatter.jp