Skip to content

Commit 5686d30

Browse files
committed
refactor(ogc): move _Fetch/_Finalize/_passthrough_result into chunking.py
These type aliases define ChunkedCall's contract, not anything about interruptions. They lived in interruptions.py only to avoid a circular import. Move them to chunking.py where they belong; interruptions.py keeps TYPE_CHECKING re-exports for backwards compat.
1 parent d6fa476 commit 5686d30

2 files changed

Lines changed: 33 additions & 24 deletions

File tree

dataretrieval/ogc/chunking.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
import asyncio
7575
import functools
7676
import os
77-
from collections.abc import Callable, Iterator
77+
from collections.abc import Awaitable, Callable, Iterator
7878
from contextlib import contextmanager
7979
from contextvars import copy_context
8080
from typing import Any, cast
@@ -88,9 +88,6 @@
8888
from . import progress as _progress
8989
from .interruptions import (
9090
ChunkInterrupted,
91-
_Fetch,
92-
_Finalize,
93-
_passthrough_result,
9491
)
9592
from .planning import (
9693
ChunkPlan,
@@ -104,6 +101,30 @@
104101
_retry,
105102
)
106103

104+
# ---------------------------------------------------------------------------
105+
# Type aliases for the ChunkedCall contract.
106+
# ---------------------------------------------------------------------------
107+
108+
# The per-sub-request fetcher the decorator wraps and ``ChunkedCall`` drives:
109+
# an ``async def fetch(args) -> (df, response)``.
110+
_Fetch = Callable[[dict[str, Any]], Awaitable[tuple[pd.DataFrame, httpx.Response]]]
111+
112+
# Caller-supplied transform applied to the combined chunk result, so a
113+
# resumed call returns the same shape as an un-interrupted one rather than
114+
# the chunker's raw ``(frame, httpx.Response)``. This keeps the chunker
115+
# generic: the OGC getters inject their post-processing (type coercion,
116+
# column arrangement, ``BaseMetadata``) through ``_finalize_ogc``.
117+
# The default is identity, so direct ``ChunkedCall`` use is unaffected.
118+
_Finalize = Callable[[pd.DataFrame, httpx.Response], tuple[pd.DataFrame, Any]]
119+
120+
121+
def _passthrough_result(
122+
frame: pd.DataFrame, response: httpx.Response
123+
) -> tuple[pd.DataFrame, Any]:
124+
"""Default :data:`_Finalize`: return the raw combined pair unchanged."""
125+
return frame, response
126+
127+
107128
# Empirically the API replies HTTP 414 above ~8200 bytes of full URL —
108129
# matches nginx's default ``large_client_header_buffers`` of 8 KB. 8000
109130
# leaves ~200 bytes for request-line framing and proxy variance. The decorator

dataretrieval/ogc/interruptions.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from __future__ import annotations
1313

14-
from collections.abc import Awaitable, Callable
1514
from typing import TYPE_CHECKING, Any, ClassVar
1615

1716
import httpx
@@ -23,25 +22,14 @@
2322
from dataretrieval.ogc.chunking import ChunkedCall
2423

2524

26-
# ``_Fetch`` is the per-sub-request fetcher the decorator wraps and
27-
# ``ChunkedCall`` drives: an ``async def fetch(args) -> (df, response)``.
28-
_Fetch = Callable[[dict[str, Any]], Awaitable[tuple[pd.DataFrame, httpx.Response]]]
29-
30-
31-
# Caller-supplied transform applied to the combined chunk result, so a
32-
# resumed call returns the same shape as an un-interrupted one rather than
33-
# the chunker's raw ``(frame, httpx.Response)``. This keeps the chunker
34-
# generic: the OGC getters inject their post-processing (type coercion,
35-
# column arrangement, ``BaseMetadata``) through ``utils._finalize_ogc``.
36-
# The default is identity, so direct ``ChunkedCall`` use is unaffected.
37-
_Finalize = Callable[[pd.DataFrame, httpx.Response], tuple[pd.DataFrame, Any]]
38-
39-
40-
def _passthrough_result(
41-
frame: pd.DataFrame, response: httpx.Response
42-
) -> tuple[pd.DataFrame, Any]:
43-
"""Default :data:`_Finalize`: return the raw combined pair unchanged."""
44-
return frame, response
25+
# These type aliases define the ChunkedCall contract and live in chunking.py;
26+
# re-exported here for backwards compatibility.
27+
if TYPE_CHECKING:
28+
from dataretrieval.ogc.chunking import _Fetch as _Fetch # noqa: F401
29+
from dataretrieval.ogc.chunking import _Finalize as _Finalize # noqa: F401
30+
from dataretrieval.ogc.chunking import ( # noqa: F401
31+
_passthrough_result as _passthrough_result,
32+
)
4533

4634

4735
class ChunkInterrupted(DataRetrievalError):

0 commit comments

Comments
 (0)