Skip to content

sorts: type shell_sort for comparable items and add tests - #15299

Closed
HarshRajSinghania wants to merge 1 commit into
TheAlgorithms:masterfrom
HarshRajSinghania:sorts/shell-sort-comparable
Closed

sorts: type shell_sort for comparable items and add tests#15299
HarshRajSinghania wants to merge 1 commit into
TheAlgorithms:masterfrom
HarshRajSinghania:sorts/shell-sort-comparable

Conversation

@HarshRajSinghania

Copy link
Copy Markdown
Contributor

Summary

Update shell_sort so it is typed and tested for any mutually comparable items, not only list[int].

Part of #15234

Motivation

Issue #15234 asks for one comparison sort per PR:

  • switch list[int] to a Comparable protocol + type parameter
  • add succeed cases for non-int comparables
  • assert TypeError when items are not comparable

shell_sort.py was still unchecked and unclaimed.

Implementation

  • Annotate shell_sort as shell_sort[T: Comparable](collection: MutableSequence[T]) -> MutableSequence[T] using the same Comparable protocol as insertion_sort / selection_sort.
  • Leave the Marcin Ciura gap-sequence implementation unchanged.
  • Add doctests for strings, mixed int/float values, and a TypeError on [1, "a"].
  • Include shell_sort in test_sort_rejects_non_comparable_items in tests/test_sorts.py. It was already in the shared SORTS battery.

Testing

Ran locally against current master:

python3 -m doctest -v sorts/shell_sort.py
# 8 passed

python3 -m pytest tests/test_sorts.py -k "shell_sort or rejects" -q
# 22 passed, 210 deselected

@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Sep 12, 2026
@algorithms-keeper

Copy link
Copy Markdown

Closing this pull request as invalid

@HarshRajSinghania, this pull request is being closed as none of the checkboxes have been marked. It is important that you go through the checklist and mark the ones relevant to this pull request. Please read the Contributing guidelines.

If you're facing any problem on how to mark a checkbox, please read the following instructions:

  • Read a point one at a time and think if it is relevant to the pull request or not.
  • If it is, then mark it by putting a x between the square bracket like so: [x]

NOTE: Only [x] is supported so if you have put any other letter or symbol between the brackets, that will be marked as invalid. If that is the case then please open a new pull request with the appropriate changes.

@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant