#154 collapse duplicated sync/async response-shaping + align retry policy - #164
Merged
Merged
Conversation
Extract transport-agnostic response-shaping into datamaxi.resources.utils (assemble_params/raise_if_no_data/to_indexed_dataframe) and premium-specific build_premium_params/shape_premium_response in resources/premium.py, imported directly by aio/premium.py and aio/cex.py. Only await/transport glue is left per-client now; sync/async can't drift on shaping. Add datamaxi/_retry.py: pure GET-only/exponential-backoff/Retry-After policy (mirrors urllib3 Retry semantics). Rewire aio/_core.py's hand-rolled loop (previously linear backoff, all methods, ignored Retry-After) onto it. Sync keeps its urllib3 Retry unchanged (well-tested, no need to touch); _retry.py is the shared description so the two can't diverge again. Also collapse api.py's duplicate _extract_limit_usage onto the one already shared via _dispatch.extract_limit_usage (used by aio already). No public API/behavior change. Extended test_endpoint_param_coverage.py's AST extractor to recognize the new params = build_x_params(x=x, ...) call-site shape alongside the existing params["x"] = ... pattern it already looked for.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #154
Summary
Collapse duplicated sync/async response-shaping and align the async retry policy with the sync (urllib3) one. Pure refactor — behavior identical, verified by an independent review pass.
Shared response-shaping (
datamaxi/resources/utils.py, leaf module — no import-cycle):assemble_params,raise_if_no_data,to_indexed_dataframeextracted.premium.py:build_premium_params(all 20 params) +shape_premium_responseextracted;aio/premium.pynow imports them directly (no async copy) — identity-tested.pd.DataFrame(...).set_index(...)/ empty-data blocks for the shared helpers.api.py: sync side now reuses_dispatch.extract_limit_usage(was duplicated).Retry alignment (
datamaxi/_retry.py, new):Retrysemantics: GET-only, backoff0thenbackoff_factor * 2**(n-1)capped at 120s,Retry-After(seconds or HTTP-date) priority.aio/_core.pyrewired onto it, replacing the old linear-backoff/all-methods/no-Retry-Afterloop (a real behavior fix). Sync side's urllib3Retryleft untouched;_retry.pyis the shared, testable description of that policy.Tests
_retry.py, shaping helpers, and sync/async premium identity). black + flake8 clean.import datamaxi/import datamaxi.aioboth OK.Reviewer nits (non-blocking, left as-is)
_retry.pyparse_retry_after: silently returnsNoneon malformedRetry-Afterand has no upper cap (urllib3 raises / caps at 21600s) — arguably safer, no real-traffic impact.test_endpoint_param_coverage.py:176; defensive dead branch inparse_retry_after.Scope note
cex_wallet_status.pyfolded into the shared helper too (issue named only candle/ticker) — same duplication pattern.