Conversation
Part of TheAlgorithms#15234 - Replace list[Any] with a Comparable-bounded TypeVar so odd_even_transposition sorts any mutually comparable items, not just ints - Add str/float/int success doctests plus a TypeError rejection doctest for non-comparable mixed input - Assert in-place behavior via `result is values` doctest - Register the sort in the shared battery and in test_sort_rejects_non_comparable_items Co-authored-by: ayushman-it <253447966+ayushman-it@users.noreply.github.com>
Member
|
@priya-sundaram-dev, please review. Are the type hints as expected? |
priya-sundaram-dev
left a comment
Contributor
There was a problem hiding this comment.
The type hints look correct to me 👍
- The PEP 695 syntax `odd_even_transposition[T: Comparable](collection: list[T]) -> list[T]` is the right call here, and returning `list[T]` (same element type) matches the in-place behavior the doctests assert (`result is values`).
- Scoping the `Comparable` protocol to just `lt` is spot-on, since `<` is the only ordering operation the algorithm actually uses — no reason to require the full rich-comparison set.
I ran the doctests and the property-style checks (random int/str samples vs `sorted()`, plus the mixed-type `TypeError` case) and they all pass on 3.12/3.13.
One tiny, optional nit: the module docstring still says "python3 -m doctest -v odd_even_transposition_single_threaded.py" — worth double-checking that filename matches after any renames, but it looks right as-is. Nice cleanup overall.
cclauss
approved these changes
Sep 23, 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.
Part of #15234
Replaces bare
list[Any]with aComparable-bounded PEP 695 type parameter soodd_even_transpositionsorts any mutually comparable items (ints, floats, strings, dataclasses, namedtuples), not just ints.ComparableProtocol + generic pattern used by the mergedreversort/`insertion_sort` PRsresult is valuesdoctest)TypeErrorrejection doctest for mixed non-comparable inputVerification
ruff check+ruff format --checkclean (ruff 0.16.7, repo config)python -m docteston the module: 18 doctests passtests/test_sorts.py: 296 battery tests pass