You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(waterdata): /simplify pass — typed RateLimited exception, drop sentinels
Pulls cleanup items out of /simplify's review:
- **Replace string-sniffing 429 detection with a typed exception.**
``_raise_for_non_200`` now raises ``utils.RateLimited`` (a
``RuntimeError`` subclass) for HTTP 429 specifically, plain
``RuntimeError`` for everything else. The chunker's ``_is_429``
walks ``__cause__`` looking for ``isinstance(_, RateLimited)``
instead of ``str(cur).startswith("429")``; ``_paginated_failure_message``
similarly switches to ``isinstance``. Any future reformatting of
the 429 message can no longer silently break quota handling.
- **Drop the ``_QUOTA_UNKNOWN = -1`` sentinel.** ``_read_remaining``
now returns ``int | None``; the wrapper branches on
``remaining is not None`` instead of comparing against a magic
number.
- **Collapse ``_finalize_response`` into ``_combine_chunk_responses``.**
The two were a 3-line wrapper around a 6-line helper; merging
them removes one call and the indirection. The combiner now takes
``canonical_url`` and sets ``.url`` directly.
- **Simplify ``_FetchOnce``** from a constrained ``TypeVar`` to a
plain ``Callable`` alias. The TypeVar required ``# type: ignore``
at the return site anyway and bought no callsite type safety.
- Update the ``waterdata_test.py`` flaky-rerun regex to match the
new ``RateLimited:`` prefix as well as ``RuntimeError:``.
Items considered and skipped:
- Planning-phase efficiency findings (redundant ``build_request``
probes, ``_filter_candidates`` joining discarded groups, dict-copy
cost in ``_iter_sub_args``) — all cold-path next to the actual HTTP
round-trips that follow. Premature optimization.
- Unifying ``_combine_chunk_responses`` with
``_finalize_paginated_response`` — they take different inputs
(one accumulates wall-clock externally, the other builds it from
the response list); unification would be churn.
- Test docstring trim — separate pass.
All 142 chunker / filter / utils unit tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments