Skip to content

fix: avoid iterating invalid margin schedules#34

Merged
stefan-jansen merged 1 commit into
mainfrom
test/assert-margin-schedule-iterator-not-consumed
Jul 11, 2026
Merged

fix: avoid iterating invalid margin schedules#34
stefan-jansen merged 1 commit into
mainfrom
test/assert-margin-schedule-iterator-not-consumed

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

Summary

  • treat only tuple/list values as margin schedule pairs during coercion, export, and validation
  • serialize arbitrary invalid iterables as scalars without consuming them
  • tighten regression coverage with a counting iterator that must not be read

Verification

  • uv run pytest tests/test_config_wiring.py::TestImmediateFill::test_invalid_margin_pct_schedule_export_keeps_non_sequences_scalar tests/test_config_wiring.py::TestImmediateFill::test_margin_pct_schedule_float_overflow_is_reported tests/test_config_wiring.py::TestImmediateFill::test_invalid_margin_pct_schedule_export_does_not_raise tests/test_config_wiring.py::TestImmediateFill::test_validate_rejects_non_numeric_margin_pct_schedule -q
  • pre-commit run --files src/ml4t/backtest/config.py tests/test_config_wiring.py

Copilot AI review requested due to automatic review settings July 11, 2026 18:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates BacktestConfig margin schedule coercion/serialization/validation to avoid accidentally iterating arbitrary iterables (e.g., generators/iterators) when handling invalid margin_pct_schedule values, preserving them as scalars during export and tightening regression coverage.

Changes:

  • Treat only list/tuple values as (initial, maintenance) schedule pairs during coercion and validation.
  • Serialize non-list/tuple invalid schedule values as scalars without consuming them.
  • Add a regression test using a counting iterator to ensure export does not read invalid iterables.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/ml4t/backtest/config.py Tightens margin schedule coercion/serialization/validation to avoid consuming arbitrary iterables.
tests/test_config_wiring.py Adds regression coverage ensuring invalid iterable values are not consumed during to_dict() export.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_config_wiring.py
@stefan-jansen stefan-jansen merged commit 0c3b12a into main Jul 11, 2026
8 checks passed
@stefan-jansen stefan-jansen deleted the test/assert-margin-schedule-iterator-not-consumed branch July 11, 2026 18:26
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.

2 participants