sorts: type intro sort for comparable items - #15403
Open
Felix-ming wants to merge 5 commits into
Open
Felix-ming wants to merge 5 commits into
Felix-ming wants to merge 5 commits into
Conversation
cclauss
reviewed
Sep 23, 2026
Member
|
@priya-sundaram-dev, please review. |
Member
|
Please add to |
priya-sundaram-dev
left a comment
Contributor
There was a problem hiding this comment.
LGTM — the PEP 695 generic conversion is correct. I ran the doctests on Python 3.12 (41/41 pass) and spot-checked further:
- The
median_of_3rewrite to use only<(to match theComparableprotocol's single__lt__) is behavior-preserving:a > b⇔b < a, so both!=branches are logically identical to the originals. Verified equal on 3000 random 3-element inputs. - 2500 random int/str arrays sort identically to
sorted(). - The new
sort([1, 'a'])doctest raisesTypeErroras expected.
One note for @Felix-ming: per cclauss's comment, wiring intro_sort into the existing tests/test_sorts.py SORTS tuple (rather than the standalone tests/test_intro_sort.py) keeps the suite consistent. Otherwise this is clean.
This was referenced Sep 23, 2026
This branch has not been deployed
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.
Describe your change
Type IntroSort and its helpers for mutually comparable items. This adds coverage for numeric and string inputs and verifies that mixed incomparable values raise
TypeError.Part of #15234
Checklist