Skip to content

sorts: make power_sort generic over comparable items - #15542

Open
LearnCodeZaid wants to merge 1 commit into
TheAlgorithms:masterfrom
LearnCodeZaid:sorts/power-sort-comparable-15234
Open

LearnCodeZaid wants to merge 1 commit into
TheAlgorithms:masterfrom
LearnCodeZaid:sorts/power-sort-comparable-15234

Conversation

@LearnCodeZaid

Copy link
Copy Markdown

Part of #15234

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests?
  • Documentation change?

Make power_sort, _find_run and _merge generic over a Comparable protocol (PEP 695 TypeVar bound) instead of bare list/Any. Add string-sorting and TypeError doctests. Register power_sort in the shared SORTS battery and the non-comparable rejection test.

Validation: pytest tests/test_sorts.py sorts/power_sort.py --doctest-modules = 447 passed. ruff check + format clean.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.

Add Comparable protocol and PEP 695 TypeVar bound so power_sort,
_find_run and _merge accept list[T] instead of bare list/Any.
Add string and TypeError doctests; register in shared SORTS
battery and non-comparable rejection test.

Part of TheAlgorithms#15234
@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed merge conflicts Open a new PR or rebase on the latest commit enhancement This PR modified some existing files labels Oct 8, 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 merge conflicts Open a new PR or rebase on the latest commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant