fix(sorts): make power_sort generic over Comparable items - #15438
Open
wanjinhao1 wants to merge 2 commits into
Open
wanjinhao1 wants to merge 2 commits into
wanjinhao1 wants to merge 2 commits into
Conversation
- Add a Comparable protocol and TypeVar bound (PEP 695) so power_sort accepts any iterable of mutually comparable items instead of bare list - Rewrite run detection and merge comparisons to use only __lt__, which is all the protocol guarantees - Add doctest + shared test battery coverage, including the mixed-type TypeError failure mode
for more information, see https://pre-commit.ci
Closing this pull request as invalid@wanjinhao1, this pull request is being closed as none of the checkboxes have been marked. It is important that you go through the checklist and mark the ones relevant to this pull request. Please read the Contributing guidelines. If you're facing any problem on how to mark a checkbox, please read the following instructions:
NOTE: Only |
wanjinhao1
force-pushed
the
agent/fix-15234-power-sort-comparable
branch
from
September 25, 2026 14:43
9e3b140 to
03e45c0
Compare
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
Checklist
Part of #15234 (does not close the tracking issue).
What
Comparableprotocol (__lt__only) and a PEP 695TypeVarbound sopower_sortaccepts any iterable of mutually comparable items (Iterable[T]→list[T]) instead of a barelist. Thekeypath staysCallable[[T], Any]per the audit note in the tracker discussion.<(the protocol guarantees nothing else): the ascending-run check>=becomesnot (... < ...)and the merge tieleft <= rightbecomesnot (right < left), which preserves stability for total orders.power_sort([1, "a"])→TypeError).power_sortin the sharedSORTSbattery and the non-comparable rejection list intests/test_sorts.py.Why
power_sort.pyis one of the remaining unchecked comparison sorts in the #15234 checklist, with no open PR and no assignee.Validation
python3 -m doctest sorts/power_sort.py— all doctests pass (including the newTypeErrorcase)python3 -m pytest tests/test_sorts.py -q— 395 passed (includes power_sort across the full shared CASES battery and the[1, "a"]rejection test)Note: one algorithm per PR per the tracker guidance. This PR was completed with AI assistance under the supervision of the account owner (@wanjinhao1) — happy to address any review feedback.