|
22 | 22 | from dataretrieval.ogc.chunking import ChunkedCall |
23 | 23 |
|
24 | 24 |
|
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 | | - ) |
33 | | - |
34 | | - |
35 | 25 | class ChunkInterrupted(DataRetrievalError): |
36 | 26 | """ |
37 | 27 | Base class for mid-stream chunk failures whose completed work is |
@@ -134,8 +124,8 @@ def partial_frame(self) -> pd.DataFrame: |
134 | 124 | """Live view of work completed so far — delegates to ``call.partial_frame``. |
135 | 125 |
|
136 | 126 | Returns an empty ``DataFrame`` when ``call`` is ``None`` (degraded / |
137 | | - unpickled state), unless a pickled snapshot was restored via |
138 | | - ``__setstate__``. |
| 127 | + unpickled state), unless a pickled snapshot was restored during |
| 128 | + unpickling. |
139 | 129 | """ |
140 | 130 | if self.call is not None: |
141 | 131 | return self.call.partial_frame |
@@ -164,24 +154,16 @@ def __getstate__(self) -> dict[str, Any]: |
164 | 154 | # resume was never possible anyway). |
165 | 155 | # |
166 | 156 | # Since ``partial_frame`` and ``partial_response`` are now live |
167 | | - # properties (delegating to ``self.call``), we must snapshot them |
168 | | - # here so the pickled state includes the data that was available |
169 | | - # at serialization time. |
| 157 | + # properties (delegating to ``self.call``), snapshot them here into |
| 158 | + # private ``_pickled_*`` keys. The base ``__setstate__`` restores |
| 159 | + # those keys via ``self.__dict__.update``, and the properties fall |
| 160 | + # back to them (through ``getattr``) once ``call`` is ``None`` — so |
| 161 | + # no ``__setstate__`` override is needed. |
170 | 162 | state = {**super().__getstate__(), "call": None} |
171 | 163 | state["_pickled_partial_frame"] = self.partial_frame.copy() |
172 | 164 | state["_pickled_partial_response"] = self.partial_response |
173 | 165 | return state |
174 | 166 |
|
175 | | - def __setstate__(self, state: dict[str, Any] | None) -> None: |
176 | | - state = state or {} |
177 | | - # Restore the pickled partial snapshots into private backing attrs |
178 | | - # that the properties will fall back to when call is None. |
179 | | - self._pickled_partial_frame = state.pop( |
180 | | - "_pickled_partial_frame", pd.DataFrame() |
181 | | - ) |
182 | | - self._pickled_partial_response = state.pop("_pickled_partial_response", None) |
183 | | - super().__setstate__(state) |
184 | | - |
185 | 167 |
|
186 | 168 | class QuotaExhausted(ChunkInterrupted): |
187 | 169 | """ |
|
0 commit comments