Whole file
mahmoud/boltons
The author described this change as “fix IndexedSet out-of-range negative indexing wrapping around (x[-n-k], pop(-n-k))”. It counts as a record because the checks below fail on the code as it stood at 609cabe93 and pass on d0a284fc7, with nothing else changed between the two runs.
Projectmahmoud/boltons
Fix saved2026-07-16
Sharing licenceBSD-2-Clause · LICENSE
Change size+3 −7
What the code was meant to do, written into the code itself as a save note
fix IndexedSet out-of-range negative indexing wrapping around (x[-n-k], pop(-n-k))
The change
| 158 | 158 | def _get_real_index(self, index): | |
| 159 | 159 | if index < 0: | |
| 160 | 160 | index += len(self) | |
| 161 | + | if index < 0 or index >= len(self): | |
| 162 | + | raise IndexError('IndexedSet index out of range') | |
| 161 | 163 | if not self.dead_indices: | |
| 162 | 164 | return index | |
| 163 | 165 | real_index = index | |
| ⋯ | |||
| 416 | 418 | else: | |
| 417 | 419 | iter_slice = self.iter_slice(start, stop, step) | |
| 418 | 420 | return self.from_iterable(iter_slice) | |
| 419 | - | if index < 0: | |
| 420 | - | index += len(self) | |
| 421 | 421 | real_index = self._get_real_index(index) | |
| 422 | - | try: | |
| 423 | - | ret = self.item_list[real_index] | |
| 424 | - | except IndexError: | |
| 425 | - | raise IndexError('IndexedSet index out of range') | |
| 426 | - | return ret | |
| 422 | + | return self.item_list[real_index] | |
| 427 | 423 | ||
| 428 | 424 | def pop(self, index=None): | |
| 429 | 425 | "pop(index) -> remove the item at a given index (-1 by default)" | |
The check that tells the two apart
fail→pass·tests/test_setutils.py::test_iset_scalar_index_bounds
fail→pass·tests/test_setutils.py::test_iset_scalar_index_multiple_dead_intervals
Check file tests/test_setutils.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 it609cabe932a1ea1423b24568644945abb1b8bb84
Broken version dated2026-07-16
Moduleboltons.setutils
Units changedIndexedSet
Fingerprintd3421cf7d35b6315
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in mahmoud/boltons
- 2026-08-06Bits
- 2026-08-06JSONLIterator
- 2026-08-06tableutils: fix Table.to_text crashes on degenerate tables and headers
- 2026-07-18backoff_iter
- 2026-07-17singularize
- 2026-07-17fix(fileutils): accept os.PathLike in AtomicSaver