One function
last in more-itertools/more-itertools
The author described this change as “fix last() when __reversed__ is None”. It counts as a record because the check below fails on the code as it stood at c834d6e4a and passes on cca32949f, with nothing else changed between the two runs.
Fix saved2025-07-14
Sharing licenceMIT · LICENSE
Change size+1 −1
What the code was meant to do, written into the code itself as a docstring
Return the last item of *iterable*, or *default* if *iterable* is empty. If *default* is not provided and there are no items in the iterable, raise `ValueError`.
The change
| 14 | 14 | if isinstance(iterable, Sequence): | |
| 15 | 15 | return iterable[-1] | |
| 16 | 16 | # Work around https://bugs.python.org/issue38525 | |
| 17 | - | if hasattr(iterable, '__reversed__'): | |
| 17 | + | if getattr(iterable, '__reversed__', None): | |
| 18 | 18 | return next(reversed(iterable)) | |
| 19 | 19 | return deque(iterable, maxlen=1)[-1] | |
| 20 | 20 | except (IndexError, TypeError, StopIteration): |
The check that tells the two apart
fail→pass·tests/test_more.py::LastTests::test_reversed_is_none
Check file tests/test_more.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itc834d6e4a0c4280b7b7750cb0de8dd8acb3d4c2c
Broken version dated2025-07-07
Modulemore_itertools.more
Units changedlast
Fingerprintd2509b7ca26e23a0
Checked2026-08-17 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in more-itertools/more-itertools
- 2026-07-19chunked
- 2026-07-03sliced
- 2026-06-30tail
- 2026-06-30interleave_evenly
- 2026-04-01windowed
- 2026-01-02nth_combination_with_replacement