Conversation
- insert_next was missing its TypeVar bound (Pyright: '<' operator invalid on T) - Protocol __lt__ takes object, not Any; order check now relies on __lt__ only - doctests: floats+ints mix, mixed [1, 'a'] raises TypeError Part of TheAlgorithms#15234
for more information, see https://pre-commit.ci
cclauss
approved these changes
Oct 1, 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.
Describe your change
Checklist
Part of #15234 (the
recursive_insertion_sort.pycheckbox).This PR types the recursive insertion sort for any comparable items:
insert_nextwas missing itsTypeVarbound, so Pyright flagged the<operator onT. Bothrec_insertion_sortandinsert_nextare now[T: Comparable]with theComparableProtocol(__lt__(self, other: object, /) -> bool), matching the pattern already checked in for other sorts in this issue.collection[index - 1] <= collection[index](which requires__le__) tonot collection[index] < collection[index - 1], so the algorithm relies on__lt__alone — same behavior, weaker protocol requirement.rec_insertion_sort([1, "a"], 2)raisesTypeError(a silent mis-sort would be a correctness bug).Verification:
The
[3, 2, 3]and[3, 2, 4, 2]doctests are unchanged, so equal-element behavior is preserved.Best,
Sam | Lead Engineer
DevilX Digital Labs
https://devilx-solution.vercel.app/