Commit 9ec2f09
sorts: make recursive_insertion_sort generic over Comparable items (#15340)
* sorts: make recursive_insertion_sort generic over Comparable items
Part of #15234
- switch rec_insertion_sort/insert_next to the Comparable/TypeVar-bound
MutableSequence[T] pattern (in-place sorts bucket) per the convention
discussed on #15234
- make rec_insertion_sort return the sorted collection and give n a
default of len(collection), so it can be called with a single
argument like the other sorts in the shared test battery
- add a string doctest
- register rec_insertion_sort in tests/test_sorts.py's shared SORTS
battery and the non-comparable-items rejection test
* fix: keep rec_insertion_sort in-place with None return, per maintainer review
- Revert n to a required parameter and drop the MutableSequence[T] return
value; rec_insertion_sort stays a pure in-place sort returning None, as
requested in review.
- Keep the Comparable/TypeVar generalization (no PEP 695 syntax, to match
the existing TypeVar style in the file).
- Keep the non-int (string) doctest.
- tests/test_sorts.py: rec_insertion_sort no longer fits the shared SORTS
battery (which asserts on a returned value), so it's removed from that
tuple and given its own parametrized in-place test, plus its own
non-comparable-items rejection test.
* test: adjust test_sorts.py for rec_insertion_sort's None-returning in-place contract
rec_insertion_sort no longer fits the shared SORTS battery (which asserts
on a returned value), so it's removed from that tuple and given its own
parametrized in-place test (checked against sorted()) plus its own
non-comparable-items rejection test.
* Apply batched suggestions from code review
Co-authored-by: Christian Clauss <cclauss@me.com>
---------
Co-authored-by: Christian Clauss <cclauss@me.com>1 parent 219478d commit 9ec2f09
2 files changed
Lines changed: 37 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
9 | 19 | | |
10 | | - | |
11 | | - | |
| 20 | + | |
| 21 | + | |
12 | 22 | | |
13 | 23 | | |
14 | | - | |
| 24 | + | |
15 | 25 | | |
16 | 26 | | |
17 | 27 | | |
| |||
27 | 37 | | |
28 | 38 | | |
29 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
30 | 45 | | |
31 | 46 | | |
32 | 47 | | |
| |||
36 | 51 | | |
37 | 52 | | |
38 | 53 | | |
39 | | - | |
| 54 | + | |
40 | 55 | | |
41 | 56 | | |
42 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| |||
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
115 | 127 | | |
116 | 128 | | |
117 | 129 | | |
| |||
136 | 148 | | |
137 | 149 | | |
138 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
0 commit comments