Current behavior
Rotator.rotate reads inputList[0] (rotator.py:7) before any length check is performed, so an empty list produces a bare IndexError: list index out of range from inside the rotation loop's setup rather than anything that names the caller's mistake. Rotator.rotateRepeat inherits the same behavior for any numRotations >= 1, while rotateRepeat([], 0) returns quietly because range(0) never enters the loop.
Verified against source at 2f70124:
rotate([]) -> RAISES IndexError list index out of range
rotateRepeat([], 0) -> []
rotateRepeat([], 1) -> RAISES IndexError list index out of range
main.py's printNumbers is affected by the same class of gap: inputList[numItems - 1] (main.py:9) evaluates to inputList[-1] on an empty list and raises the same bare IndexError.
Why this is worth deciding
The current behavior is now locked in by characterization tests (test_rotate_empty_raises, test_empty_1r_raises, test_printNumbers_empty_raises), so it will not change silently. What has never been decided is whether an empty list should be treated as an error at all — rotating nothing is arguably a well-defined no-op — and, if it is an error, whether the message should say so.
Options
- Treat an empty list as a no-op, returning early from
rotate when len(inputList) == 0.
- Keep it an error, but raise with an explanatory message instead of letting a raw index access fail.
- Leave the behavior as-is and consider the characterization tests sufficient documentation.
Whichever option is chosen, the existing characterization tests must be updated in the same change rather than deleted, and the in-place, no-copy constraint stated in README.md must be preserved.
This issue body was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
drafted by Claude on behalf of Daniel Stephenson
Current behavior
Rotator.rotatereadsinputList[0](rotator.py:7) before any length check is performed, so an empty list produces a bareIndexError: list index out of rangefrom inside the rotation loop's setup rather than anything that names the caller's mistake.Rotator.rotateRepeatinherits the same behavior for anynumRotations >= 1, whilerotateRepeat([], 0)returns quietly becauserange(0)never enters the loop.Verified against source at
2f70124:main.py'sprintNumbersis affected by the same class of gap:inputList[numItems - 1](main.py:9) evaluates toinputList[-1]on an empty list and raises the same bareIndexError.Why this is worth deciding
The current behavior is now locked in by characterization tests (
test_rotate_empty_raises,test_empty_1r_raises,test_printNumbers_empty_raises), so it will not change silently. What has never been decided is whether an empty list should be treated as an error at all — rotating nothing is arguably a well-defined no-op — and, if it is an error, whether the message should say so.Options
rotatewhenlen(inputList) == 0.Whichever option is chosen, the existing characterization tests must be updated in the same change rather than deleted, and the in-place, no-copy constraint stated in
README.mdmust be preserved.This issue body was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
drafted by Claude on behalf of Daniel Stephenson