Skip to content

Fix empty and non-advancing chunk ranges - #569

Open
ac1982 wants to merge 1 commit into
mahmoud:masterfrom
ac1982:fix/chunk-range-boundaries
Open

ac1982 wants to merge 1 commit into
mahmoud:masterfrom
ac1982:fix/chunk-range-boundaries

Conversation

@ac1982

@ac1982 ac1982 commented Oct 8, 2026

Copy link
Copy Markdown

The change

Handle empty inputs and reject non-advancing overlap in chunk_ranges before alignment arithmetic:

list(chunk_ranges(0, 5, align=True))  # currently [(0, 0)], expected []
list(chunk_ranges(12, 5, overlap_size=6))  # currently [], expected ValueError

An overlap equal to the chunk size currently raises a ZeroDivisionError with alignment, versus a range() error without it. Validate overlap_size < chunk_size consistently, and return no ranges for an empty input. Document both constraints and test alignment on/off, multiple offsets, and equal/greater overlap values. Existing valid chunk examples remain covered.

Validation on Linux/Python 3.12: the new tests produced 10 failures before the fix. python -m pytest --doctest-modules boltons tests -q after the fix: 692 passed, 12 subtests passed. Other Python versions and operating systems were not run locally. Searched open/closed issues and PRs for chunk_ranges, chunk ranges, overlap, and empty chunks; found the original implementation PR #312 but no matching fix.

The backstory

This contribution comes from ac1982's 30-day experiment evaluating whether AI-produced fixes are accepted by open-source maintainers. Codex found this while inspecting iterator boundary behavior; this is not a failure encountered in a production application, and we are not claiming a history of using boltons. The useful observation was that alignment emits an initial range before checking whether the input contains any elements, while overlap determines whether traversal can advance at all.

AI assistance

  • Harness/tooling: OpenAI Codex, repository inspection, shell, pytest, GitHub CLI.
  • Model: GPT-6-based Codex.
  • Original task prompt: “OK,继续今天的工作吧,magpie 只算做 addtional 任务,不记作当前天的 30,所以今天总共任务是 32 个。” Earlier instructions require reproducing real bugs, reading contribution rules, searching existing PRs, minimal fixes and regression tests; PR quantity must not lower quality. No boltons-specific bug prompt was supplied; Codex selected and implemented this boundary fix during that work.

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked chunk coverage over empty and nonempty sizes, three offsets, three chunk sizes, every valid overlap, and both alignment modes. The output covers exactly the requested positions, every chunk is nonempty and bounded, and successive starts strictly advance. Overlap equal to or greater than the chunk size raises ValueError.

Checked b718bdbabbea with standalone Python 3.12.14 checks (1,082 passing assertions). I haven't run the full upstream suite.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants