Skip to content

fix(loaders): align fetch() signature with DataLoaderProtocol in 3 loaders#437

Closed
shadowinlife wants to merge 1 commit into
HKUDS:mainfrom
shadowinlife:fix/loader-fetch-signature
Closed

fix(loaders): align fetch() signature with DataLoaderProtocol in 3 loaders#437
shadowinlife wants to merge 1 commit into
HKUDS:mainfrom
shadowinlife:fix/loader-fetch-signature

Conversation

@shadowinlife

Copy link
Copy Markdown
Contributor

Summary

Three data loaders (tushare, okx, yfinance) define fetch() with fields and interval as positional parameters in the wrong order, violating the DataLoaderProtocol contract which declares them keyword-only (after *).

Closes #436.

Changes

File Before After
agent/backtest/loaders/tushare.py:67 fetch(self, codes, start, end, fields=None, interval="1D") fetch(self, codes, start, end, *, interval="1D", fields=None)
agent/backtest/loaders/okx.py:50 Same Same
agent/backtest/loaders/yfinance_loader.py:227 Same Same

Two fixes per signature:

  1. Add * keyword-only separator — prevents positional misuse
  2. Reorder interval before fields — matches Protocol definition and all 16 other compliant loaders

Impact

  • Latent bug — no current caller passes interval/fields as positional args, so behavior is unchanged
  • Prevents future misuseloader.fetch(codes, start, end, "1D") would silently pass "1D" as fields on these 3 loaders but work correctly on the other 16
  • Protocol compliance@runtime_checkable Protocol check cannot catch parameter-ordering differences; this fix eliminates the divergence at the source

Testing

  • test_tushare_loader.py: 55 passed, 4 skipped
  • test_registry.py: 23 passed
  • test_loader_retry_helpers.py + test_ohlc_validation.py + test_engine_robustness.py: 58 passed
  • test_local_loader.py + test_mootdx_loader.py + test_eastmoney_loader.py + test_stooq_loader.py + test_futu_loader.py: 76 passed
  • Verified all call sites in runner.py, benchmark.py, correlation.py, grounding.py, market_data.py, base.py, options_portfolio.py, ui_services.py use keyword arguments only

…aders

tushare, okx, and yfinance loaders defined fetch() with fields and interval
as positional parameters in the wrong order, violating the DataLoaderProtocol
contract which declares them keyword-only (after *).

Add the * keyword-only separator and reorder to interval before fields,
matching the Protocol and all 16 other compliant loaders.

No behavioral change — all existing call sites use keyword arguments.

Closes HKUDS#436

Signed-off-by: shadowinlife <shadowinlife@gmail.com>
warren618 added a commit that referenced this pull request Jul 9, 2026
Fix Docker/server startup when mounted router-like routes do not expose path.
Preserve the first CLI turn entered at the resume prompt, align loader fetch signatures, refresh Codex OAuth defaults, add Kimi for Coding and opencode-compatible provider mappings, and clean up Tushare reference fence typos.

Fixes #450.
Integrates #437, #448, #446, #435, #449, #444.
Reported-by: Penn-Live
Co-authored-by: shadowinlife <shadowinlife@gmail.com>
Co-authored-by: morluto <williamlin1327@gmail.com>
Co-authored-by: Carls <yxhuang@uibe.edu.cn>
Co-authored-by: Sankalp Singh <iamsankz@gmail.com>
Co-authored-by: flash1234pku <53250768+flash1234pku@users.noreply.github.com>
@warren618

Copy link
Copy Markdown
Collaborator

Thanks @shadowinlife. I integrated this loader signature fix into main in 04ccb21, with focused loader/backtest coverage passing. You are credited in the commit via Co-authored-by. Closing this PR because the equivalent change is now on main.

@warren618 warren618 closed this Jul 9, 2026
@shadowinlife shadowinlife deleted the fix/loader-fetch-signature branch July 13, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(loaders): 3 loaders violate DataLoaderProtocol fetch() signature — latent parameter-ordering bug

2 participants