Skip to content

Fix merge sort comparable clean - #15259

Merged
cclauss merged 10 commits into
TheAlgorithms:masterfrom
kadubhumika:fix-merge-sort-comparable-clean
Sep 9, 2026
Merged

Fix merge sort comparable clean#15259
cclauss merged 10 commits into
TheAlgorithms:masterfrom
kadubhumika:fix-merge-sort-comparable-clean

Conversation

@kadubhumika

Copy link
Copy Markdown
Contributor

Description

Makes merge_sort.py support any comparable items instead of only relying on untyped lists.

Changes:

  • Added a Comparable protocol
  • Added a bounded TypeVar
  • Updated merge_sort() to use generic type hints
  • Added doctests for strings and floats

Part of #15234

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. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • [] All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files tests are failing Do not merge until tests pass labels Sep 9, 2026
@github-actions
github-actions Bot force-pushed the fix-merge-sort-comparable-clean branch from 4425c11 to a4c0f55 Compare September 9, 2026 19:32
@algorithms-keeper algorithms-keeper Bot removed the tests are failing Do not merge until tests pass label Sep 9, 2026
@kadubhumika

Copy link
Copy Markdown
Contributor Author

Hi! The PR is ready for review. The latest changes have been pushed and the pre-commit checks are passing. The remaining workflows are currently awaiting maintainer approval. Thank you!

Corrected minor grammatical errors in docstring.
@cclauss

cclauss commented Sep 9, 2026

Copy link
Copy Markdown
Member

@priya-sundaram-dev, your review, please.

@priya-sundaram-dev priya-sundaram-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kadubhumika — the merge_sort.py change itself looks good. The Comparable protocol with just __lt__, the PEP 695 merge_sort[T: Comparable] generic, and the switch to a strict < comparison (which keeps the sort stable and only depends on the one dunder the protocol declares) are all consistent. I verified it against ints, floats, and strings and the doctests pass.

One thing to fix before this can go in: the diff also touches DIRECTORY.md with a bunch of unrelated machine-learning / physics / neural-network entries. Those aren't part of this change — they're an artifact of the branch being behind master. Could you sync your branch with upstream master and revert DIRECTORY.md so this PR only touches sorts/merge_sort.py? (The checklist item "This PR only changes one algorithm file" is what the maintainers look for.) Once DIRECTORY.md is clean this is good to go from my side.

@cclauss

cclauss commented Sep 9, 2026

Copy link
Copy Markdown
Member

It is important to always refresh your master branch before creating each new pull request.

@cclauss
cclauss enabled auto-merge (squash) September 9, 2026 22:21
@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 9, 2026
@cclauss
cclauss disabled auto-merge September 9, 2026 22:23
@cclauss
cclauss merged commit 9e84598 into TheAlgorithms:master Sep 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants