Whole file

mahmoud/boltons

The author described this change as fix IndexedSet slicing after removals: keep iter_slice bounds in apparent index space (#423). It counts as a record because the checks below fail on the code as it stood at 979fa9b61 and pass on 609cabe93, with nothing else changed between the two runs.

Fix saved2026-07-16
Sharing licenceBSD-2-Clause · LICENSE
Change size+10 4

What the code was meant to do, written into the code itself as a save note

fix IndexedSet slicing after removals: keep iter_slice bounds in apparent index space (#423)

The change

392392 def iter_slice(self, start, stop, step=None):
393393 "iterate over a slice of the set"
394394 iterable = self
395- if start is not None:
396- start = self._get_real_index(start)
397- if stop is not None:
398- stop = self._get_real_index(stop)
395+ # start/stop are apparent (dead-slot-free) indices, the same space
396+ # islice consumes; mapping them through _get_real_index() (item_list
397+ # space) over-counted by the dead slots before each bound. Only
398+ # negatives need normalizing, as islice rejects them.
399+ # NB: a negative step slices the reversed stream with forward bounds
400+ # (x[2:4:-1] == reversed(x)[2:4]), behavior since 2013.
401+ if start is not None and start < 0:
402+ start = max(len(self) + start, 0)
403+ if stop is not None and stop < 0:
404+ stop = max(len(self) + stop, 0)
399405 if step is not None and step < 0:
400406 step = -step
401407 iterable = reversed(self)

The check that tells the two apart

failpass·tests/test_setutils.py::test_iset_slice_after_removal
failpass·tests/test_setutils.py::test_iset_slice_agreement

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 it979fa9b613fa8c0a455ae16ea6f2ec91c11ecafe
Broken version dated2026-06-18
Moduleboltons.setutils
Units changedIndexedSet
Fingerprintb4a3688d258528e4
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