Skip to content

Reject non-integer pagination bounds in iter_reviews - #80

Open
VictortheGreat7 wants to merge 1 commit into
prooflinedev:mainfrom
VictortheGreat7:fix/page-limits-integers
Open

VictortheGreat7 wants to merge 1 commit into
prooflinedev:mainfrom
VictortheGreat7:fix/page-limits-integers

Conversation

@VictortheGreat7

@VictortheGreat7 VictortheGreat7 commented Nov 22, 2026 •

Copy link
Copy Markdown

Problem

_page_limits (used by iter_reviews, sync and async) only compares its arguments with <=, so it accepts values that are not valid integers. Calling it directly on main:

Argument Value Result on main
page_size 2.5 accepted
page_size True accepted
max_pages 2.5 accepted
max_items 2.5 accepted
page_size "10" TypeError

Through the iterator, max_items="10" fails with TypeError: '<=' not supported between instances of 'int' and 'str', while out-of-range numbers raise the documented ValueError.

This has a real effect for max_items. The loop checks count == max_items, which can never be true for a float, so the documented pagination-limit bound never fires. With a server that returns two items and max_items=1.5, iter_reviews yielded both items and raised nothing, in sync and async mode. With max_items=1 the same server raises pagination-limit.

_export_page_limit already rejects bools and non-integers, so the reviews iterator was inconsistent with it.

max_items=1.5 demonstration (throwaway test, not committed)
@MODES
async def test_tmp_float_max_items(mode: str) -> None:
    two_items = page()
    two_items["items"].append(dict(two_items["items"][0]))
    with Server(lambda request, index: Reply(body=two_items)) as server:
        async with session(mode, server.url) as client:
            items = await collect(client, max_items=1.5, filters={"cursor": "initial"})
            print("yielded", len(items), "items with max_items=1.5")
  • main: yielded 2 items with max_items=1.5 (sync and async)
  • this branch: ValueError: Pagination requires page_size 1..100, max_pages 1..1000, max_items 1..100000. before any request

Fix

def _in_range(value: object, low: int, high: int) -> bool:
    return isinstance(value, int) and not isinstance(value, bool) and low <= value <= high


def _page_limits(page_size: int, max_pages: int, max_items: int) -> None:
    if not (
        _in_range(page_size, 1, 100)
        and _in_range(max_pages, 1, 1_000)
        and _in_range(max_items, 1, 100_000)
    ):
        raise ValueError(
            "Pagination requires page_size 1..100, max_pages 1..1000, max_items 1..100000."
        )

The ranges and the ValueError message are unchanged. Behaviour change: values that are not integers, such as "10", now raise ValueError instead of TypeError.

Tests

30 new cases in tests/test_http.py, each run in sync and async mode against the loopback server, asserting that no request reaches it:

  • 12 range checks (0 and one above the maximum for each argument), which pass before and after and guard against loosening the existing limits
  • 18 non-integer checks (True, 1.5, "10" for each argument), which fail on main and pass here

To reproduce the failures:

git checkout upstream/main -- proofline/client.py
pytest tests/test_http.py -k reviews_iterator    # 18 failed, 12 passed
git checkout HEAD -- proofline/client.py
pytest tests/test_http.py -k reviews_iterator    # 30 passed

Not included

  • Export code. _export_page_limit has the same check inline and could use _in_range; I left it alone to avoid conflicts with the open export PRs, and behaviour would not change.
  • iter_reviews is a generator, so the ValueError is raised on first iteration, not at call time. iter_export_pages behaves the same way and its tests rely on it, so I left it.

Checks

python3 scripts/check.py passes locally: generation check, contracts, ruff, mypy, 249 tests (8 subtests), and sdist and wheel installs. Run on Linux with Python 3.14.4; CI pins 3.13.12.

Proofline review

I installed Proofline on my fork and it reviewed this change there: VictortheGreat7#1

The review completed on commit f6f0588 (base 1f389da), before I rebased onto the current main, and reported no findings. From the API: the code assessment ran for about 30 seconds and completed with an empty findings list.

Because it gave me nothing to act on, I conducted a diff review with help:

  • Error message. It doesn't say which argument failed. I kept the existing text so nothing that matches it breaks; naming the argument would be a small follow-up if you want it.
  • Types and contracts. mypy (strict) and the contract check pass; no public method changed.
  • Strictness. isinstance(value, int) rejects NumPy integer types, as _export_page_limit
    does. operator.index would accept them while still rejecting floats; I chose consistency.
  • Docs. Nothing to change in docs. README only mentions max_pages for the export iterator (it already says "an integer from 1 to 1000", consistent with this change).

AI assistance: I used Claude in a chat window for explanations and to draft the helper, the test shapes and this description. I ran, adapted and verified everything locally.

@VictortheGreat7 VictortheGreat7 changed the title fix: reject non-integer pagination bounds Reject non-integer pagination bounds in iter_reviews Nov 23, 2026

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.

1 participant