Skip to content

refactor(trading-suite): make Features a StrEnum for ruff 0.16 (unblocks #154) - #155

Merged
TexasCoding merged 2 commits into
mainfrom
maint/154-features-strenum
Oct 4, 2026
Merged

TexasCoding merged 2 commits into
mainfrom
maint/154-features-strenum

Conversation

@TexasCoding

Copy link
Copy Markdown
Owner

Unblocks #154 (Dependabot python-patch group), whose lint job fails under ruff 0.16.9:

UP042 Class Features inherits from both `str` and `enum.Enum`
   --> src/project_x_py/trading_suite.py:155:7

Approved by the owner on 2026-10-04.

Changes

  • Features in trading_suite.py is now enum.StrEnum (was str, Enum).
    • Behavior change: str(Features.X) and f-strings / format() now return the value (e.g. "orderbook") instead of "Features.ORDERBOOK".
    • Unchanged: members and values, isinstance(..., str), equality with plain strings, Features("orderbook"), hashing, .value, json.dumps, repr.
  • New tests/trading_suite/test_features.py (11 tests: str/f-string, equality, hashing, JSON serialization, config and TradingSuite.create(features=[...]) with strings). Written test-first; the 5 str/format/StrEnum tests failed before the change.
  • ruff 0.16 format fixes in src/ (the "2 files would be reformatted" issue), accepted by both ruff 0.12.8 and 0.16.9:
    • indicators/overlap.py: WMA rolling_map lambda body is now in parentheses (no logic change)
    • utils/README.md: Python code fences reformatted (ruff 0.16 now formats Markdown)
  • CHANGELOG [Unreleased] → ### Changed entry.

I searched src/, tests/, docs/, examples/ and README for code that depends on the old "Features.X" string output and found none. The code uses membership checks, .value, or repr (the init log formats a list, so it still shows the repr). The docs don't mention the base class or the str() output, so no docs changes were needed.

uv.lock and pyproject.toml are unchanged.

Gates

  • uv run ruff check src/ / uv run ruff format --check src/ (0.12.8): pass
  • uvx ruff@0.16.9 check src/ / uvx ruff@0.16.9 format --check src/: pass
  • uv run mypy src/: pass
  • uv run pytest tests/trading_suite: 112 passed
  • uv run pytest -m "unit and not slow": 2735 passed, 1 failed. The failure (test_get_bars_since_with_pytz_timezone_object, ZoneInfoNotFoundError: 'US/Eastern', local tzdata) also fails on main.
  • ./check_quality.sh: the failures also happen on main and are outside src/ (76 unformatted files and 39 ruff findings in tests/, examples/, scripts/). This PR doesn't touch those files.

Switch Features from (str, Enum) to enum.StrEnum so ruff 0.16 UP042
passes. str() and f-strings now return the value (e.g. "orderbook")
instead of "Features.X"; equality, .value, and JSON serialization are
unchanged. Unblocks Dependabot #154.
Parenthesize the WMA rolling_map lambda and format Python fences in
src/project_x_py/utils/README.md so src/ passes both ruff 0.12.8 and
0.16.9 format --check.
@TexasCoding
TexasCoding merged commit 7f9468d into main Oct 4, 2026
7 checks passed
TexasCoding added a commit that referenced this pull request Oct 4, 2026
…1.44)

#155 clears the ruff 0.16 lint finding in Dependabot #154, but #154 stays blocked on mypy errors from its polars 1.44.2 bump, so don't say #155 unblocks it.
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.

1 participant