sorts: support comparable items in circle_sort - #15244
Merged
cclauss merged 5 commits intoSep 9, 2026
Merged
Conversation
Member
|
@priya-sundaram-dev your review, please. |
priya-sundaram-dev
left a comment
Contributor
There was a problem hiding this comment.
Thanks @hzagaming — this is close! A few things I really like:
- Switching the comparisons to
collection[right] < collection[left]so the code only relies on__lt__, matching theComparableprotocol. 👍 - The
circle_sort([1, "a"])TypeErrordoctest is a great edge case. - Nice catch fixing the broken inner doctest (
lst→arr) and wiringcircle_sortintotests/test_sorts.py.
One cleanup before I approve: the module-level T = TypeVar("T", bound=Comparable) (and the TypeVar import) is now dead code, since the function uses the PEP 695 def circle_sort[T: Comparable](...) type parameter instead. Please drop both so we don't have two competing T definitions — that keeps it consistent with the other sorts in #15234 (e.g. selection_sort). After that it's good to go. Ran the doctests locally — all 8 pass. 🙌
cclauss
reviewed
Sep 9, 2026
Co-authored-by: Christian Clauss <cclauss@me.com>
cclauss
enabled auto-merge (squash)
September 9, 2026 21:56
cclauss
approved these changes
Sep 9, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Update
circle_sortto support arbitrary comparable items instead of only integer-typed lists.Changes
Comparableprotocol and generic type parameterMutableSequence[T]<consistently so the implementation matches theComparableprotocolcircle_sort_utildoctest variable typoRelated to #15234.
Test
python -m doctest -v sorts/circle_sort.pypython -m pytest tests/test_sorts.py -vruff check sorts/circle_sort.py tests/test_sorts.pyruff format --check sorts/circle_sort.py tests/test_sorts.pygit diff --check