feat: consistent return shape via last_response metadata (#140)#145
Merged
Conversation
…hape Closes #140 send_request wrapped rate-limit/header info into the return only when show_limit_usage/show_header were set, so the return type branched on a constructor flag. Worse, the wrapper keyed metadata under 'data' — colliding with the backend's own {"data": ...} envelope — so the wrapped path corrupted every DataFrame-returning method (res['data'] became the whole backend dict). Now send_request always returns the payload and records a ResponseMeta (status_code, headers, limit_usage, data) on api.last_response, forwarded as a property on Resource (client.<resource>.last_response). Non-flag callers see no change; the flags are kept for back-compat but marked deprecated and no longer alter the return shape.
Proper option-2 deprecation: the flags still work as before (no-op on return shape) but now warn on use, so callers get a runtime nudge before a future major removes them. Assert the warning in tests (and no warning when the flags are absent/False).
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 #140
Summary
send_requestreturned a bare payload normally, but a{"data": ..., "limit_usage": ..., "header": ...}wrapper whenshow_limit_usage/show_headerwas set — so the return type branched on a constructor flag.Worse, while tracing it I found the wrapper keyed metadata under
"data", which collided with the backend's own{"data": ...}envelope. Resource methods dores["data"]expecting the backend list, so the wrapped path handed them the whole backend dict instead — silently corrupting every DataFrame-returning method (cex.candle,cex.ticker,funding_rate,premium, ...). Those flags were effectively broken.Change (side-channel metadata — the approved approach)
send_requestalways returns the payload (DataFrame / backend dict, exactly as a plain client already did).api.last_responseas a smallResponseMeta(status_code, headers, limit_usage, data), surfaced as alast_responseproperty onResource→client.<resource>.last_response. Since the tree shares one transport (refactor: share one Session across the client tree via composition (#2, #3) #137), it reflects the last call through it.show_limit_usage/show_headerare deprecated (option-2 lifecycle): still accepted and stored, no longer change the return shape, and now emit aDeprecationWarningwhen passed truthy so callers get a runtime nudge before a future major removes them.Compatibility
DeprecationWarning; read metadata fromlast_response. The old wrapped path was buggy/inconsistent (see above), so this is a net fix.Tests
tests/test_last_response.py(6 tests):last_responseNonebefore any call; populated after; flags don't wrap the return; shared across the client tree; deprecation warning emitted for each flag; no warning when flags absent/False.tests/test_api.pyflag tests to assert theDeprecationWarning.pytest -m "not integration": 145 passed, 11 skipped.Known failures
None.