Skip to content

fix: deprecate nonpositive batch sizes before 5.0 - #64

Merged
wolph merged 4 commits into
wolph:developfrom
tongwentao:fix/positive-batch-size
Oct 29, 2026
Merged

wolph merged 4 commits into
wolph:developfrom
tongwentao:fix/positive-batch-size

Conversation

@tongwentao

Copy link
Copy Markdown
Contributor

This replaces closed PR #62 with the compatibility changes requested in the maintainer's review. GitHub does not allow the contributor account to reopen #62.

Sizes below 1 have been accepted since batcher was introduced. Rejecting them immediately would break existing 4.x callers, including batcher([], 0) and sizes computed from a small input. This revision follows the maintainer's compatibility plan: warn in 4.x and reserve ValueError for 5.0.

  • batcher emits one DeprecationWarning for a size below 1 when iteration begins, before consuming the source. Its existing result is preserved: one batch containing all items, or no batches for an empty source.
  • Without an interval, abatcher emits the same warning and preserves existing behavior, including the assertion for size 0 and the single final batch for a negative size.
  • With an interval, abatcher accepts None, 0 and negative sizes as no size limit, without warning. Interval deadlines and cancellation behavior remain covered by the existing tests, now also exercised with 0 and -1.
  • Warnings point to the caller. Callers who turn deprecations into errors fail before any source items are consumed or scheduled. Positive sizes retain lazy, bounded consumption and issue no warning.

Both docstrings and the changelog explain the staged deprecation. This PR does not implement the future 5.0 exception.

Validation on Python 3.13.5, using the existing development environment over SSH on Linux:

  • Full tests and doctests: 405 passed, 100% statement and branch coverage.
  • Batching module: 51 passed, covering empty/nonempty sources, warning timing/category/location, warnings promoted to errors, positive sizes, and interval-only behavior and deadlines.
  • Ruff lint and format, Mypy, basedpyright, Pyrefly and Codespell passed.
  • Sphinx HTML build with warnings treated as errors passed.

Other interpreter versions are left to CI. This revision was prepared and validated with Codex.

@wolph
wolph merged commit dc831d0 into wolph:develop Oct 29, 2026
17 checks passed
wolph added a commit that referenced this pull request Oct 29, 2026
The size check from #64 compared every size with 1, so a str or complex
size that batcher and abatcher used to accept now raised TypeError. With
an interval it also turned a size of 0 into None, which stopped the empty
batch that abatcher yields for an idle interval. The check now only
warns, and leaves sizes it cannot compare and sizes used with an interval
as they were.
wolph added a commit that referenced this pull request Oct 29, 2026
@wolph

wolph commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thank you for picking this back up, and for following the plan so closely :)

I've added one fix on top (98ae27f). A size that doesn't compare with 1, such as a string read from a config file, gave one batch on 4.1.4 and raised a TypeError with this change. abatcher(source, 0, interval) also stopped yielding the empty batch for an idle interval. Both behave as they did in 4.1.4 again.

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