Skip to content

fix(sorts): accept lt-only items in recursive insertion sort - #15436

Open
tuttucodes wants to merge 1 commit into
TheAlgorithms:masterfrom
tuttucodes:fix/recursive-insertion-comparable
Open

tuttucodes wants to merge 1 commit into
TheAlgorithms:masterfrom
tuttucodes:fix/recursive-insertion-comparable

Conversation

@tuttucodes

Copy link
Copy Markdown

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Existing doctests remain unchanged.
  • Documentation change?

insert_next used <=, so a collection whose elements implement only < raised TypeError even though those elements are orderable. Compare the next element with < instead and bind the generic type parameter to Comparable. Add a shared regression case with a custom <-only element. Existing sort tests cover strings, floats, and the mixed-type TypeError case.

Part of #15234. This is one algorithm from the umbrella issue, so the issue should remain open.

Verification

  • python3.14 -m doctest sorts/recursive_insertion_sort.py
  • uvx --python 3.14 pytest tests/test_sorts.py -q — 384 passed
  • uvx ruff check sorts/recursive_insertion_sort.py tests/test_sorts.py
  • uvx ruff format --check sorts/recursive_insertion_sort.py tests/test_sorts.py
  • uvx pre-commit run --all-files

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is original work and does not copy another implementation.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file and its shared regression test.
  • All modified function parameters and return values have type hints.
  • The existing algorithm functions have passing doctests.
  • All new Python files are placed inside an existing directory. -- No new files.
  • All new algorithms include an explanatory URL. -- No new algorithm.
  • This PR closes an issue. -- sorts: make algorithms sort any comparable items, not just ints #15234 tracks several remaining algorithms.

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Sep 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant