Refactor: consolidate duplicated _elapsed_ms and remove one-liner wrapper#34
Merged
Refactor: consolidate duplicated _elapsed_ms and remove one-liner wrapper#34
Conversation
…pper _elapsed_ms() was copy-pasted identically into all six validation check modules (ruff_check, mypy_check, interface_check, lookahead_check, feature_check, resource_check). Extracted to validation/_utils.py and replaced each local definition with an import. BacktestEngine._parse_zone() was a one-line wrapper that called the module-level _parse_zone() function with self._products[0]. Inlined the call at the single use site and removed the method. https://claude.ai/code/session_01XqYtc2t1oCV8eTmXN8aaiY
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR reduces duplication in the validation subsystem by extracting a shared _elapsed_ms() helper into a single module, and simplifies the backtest engine by removing an unnecessary one-line wrapper method.
Changes:
- Added
validation/_utils.pyas the shared home for_elapsed_ms(start: float) -> int. - Updated all six validation check modules to import
_elapsed_msinstead of defining it locally. - Inlined
BacktestEngine._parse_zone()usage at the only call site and removed the wrapper method.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/nexa_backtest/validation/_utils.py | Introduces a shared _elapsed_ms() helper used across validation checks. |
| src/nexa_backtest/validation/ruff_check.py | Replaces local _elapsed_ms implementation with an import from _utils. |
| src/nexa_backtest/validation/mypy_check.py | Replaces local _elapsed_ms implementation with an import from _utils. |
| src/nexa_backtest/validation/interface_check.py | Replaces local _elapsed_ms implementation with an import from _utils. |
| src/nexa_backtest/validation/lookahead_check.py | Replaces local _elapsed_ms implementation with an import from _utils. |
| src/nexa_backtest/validation/feature_check.py | Replaces local _elapsed_ms implementation with an import from _utils. |
| src/nexa_backtest/validation/resource_check.py | Replaces local _elapsed_ms implementation with an import from _utils. |
| src/nexa_backtest/engines/backtest.py | Inlines _parse_zone(self._products[0]) and removes the redundant wrapper method. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
_elapsed_ms()was copy-pasted identically into all six validation check modules. Extracted to a newvalidation/_utils.pyand replaced each local definition with an import.BacktestEngine._parse_zone()was a one-line method that only called the module-level_parse_zone()withself._products[0]. Inlined and removed.Changes
src/nexa_backtest/validation/_utils.py(new file)Shared home for
_elapsed_ms(start: float) -> int— the single source of truth.6 validation modules (
ruff_check,mypy_check,interface_check,lookahead_check,feature_check,resource_check)Removed local
_elapsed_msdefinition, addedfrom nexa_backtest.validation._utils import _elapsed_ms.src/nexa_backtest/engines/backtest.pyRemoved
BacktestEngine._parse_zone()wrapper method. Inlined_parse_zone(self._products[0])at the one call site.Test plan
make cipasses — 727 tests, ruff check clean, ruff format cleanhttps://claude.ai/code/session_01XqYtc2t1oCV8eTmXN8aaiY