Skip to content

fix(strategies): remove IRON_BUTTERFLY enum alias that shadowed BUTTERFLY (#4)#26

Open
bradsmithmba wants to merge 1 commit into
cloudtrainerwork:masterfrom
bradsmithmba:fix/iron-butterfly-enum
Open

fix(strategies): remove IRON_BUTTERFLY enum alias that shadowed BUTTERFLY (#4)#26
bradsmithmba wants to merge 1 commit into
cloudtrainerwork:masterfrom
bradsmithmba:fix/iron-butterfly-enum

Conversation

@bradsmithmba

Copy link
Copy Markdown

Summary

StrategyType defined two members with the same value:

BUTTERFLY = "butterfly"
IRON_BUTTERFLY = "butterfly"

In Python, identical enum values make the second member a silent alias of the first:

>>> StrategyType.IRON_BUTTERFLY is StrategyType.BUTTERFLY
True
>>> {StrategyType.BUTTERFLY: 'a', StrategyType.IRON_BUTTERFLY: 'b'}
{<StrategyType.BUTTERFLY: 'butterfly'>: 'b'}   # one key, 'a' silently dropped

Any code that used both as distinct dictionary keys (probabilities, risk metrics, score maps) would silently lose one entry.

Closes #4.

Why remove rather than make distinct

The codebase canonically identifies the iron butterfly as BUTTERFLY:

  • IronButterflyStrategy.get_strategy_type() returns StrategyType.BUTTERFLY
  • the factory registry maps StrategyType.BUTTERFLY -> IronButterflyStrategy
  • regime mappings, recommendation_engine, the API layer, and the curriculum all key on BUTTERFLY
  • there is only one butterfly-family implementation

IRON_BUTTERFLY was referenced in exactly one place: tests/models/test_scoring_engine.py. Making it a distinct value would create an orphan enum member with no implementation and no factory mapping. Removing the redundant alias and pointing that test at the canonical BUTTERFLY is the minimal correct fix.

Changes

  • src/strategies/base.py: remove IRON_BUTTERFLY = "butterfly"; add a comment explaining BUTTERFLY is the canonical iron-butterfly member.
  • tests/models/test_scoring_engine.py: StrategyType.IRON_BUTTERFLY -> StrategyType.BUTTERFLY (3 references).

Verification

StrategyType has IRON_BUTTERFLY:  False
StrategyType member count:        16   (unchanged — the alias was never a distinct member)

$ pytest tests/models/test_scoring_engine.py tests/strategies/ -q
149 passed

Note

The naming is still imperfect — BUTTERFLY represents an iron butterfly. Renaming BUTTERFLY -> IRON_BUTTERFLY across the ~30 references in 10+ files would better reflect the implementation, but that is a larger refactor and out of scope for this fix.

🤖 Generated with Claude Code

…RFLY

StrategyType defined both BUTTERFLY = "butterfly" and IRON_BUTTERFLY =
"butterfly". Identical values make IRON_BUTTERFLY a silent alias of
BUTTERFLY (StrategyType.IRON_BUTTERFLY is StrategyType.BUTTERFLY), so the
two collapse to one dict key — using both in a probabilities/metrics dict
silently drops one entry.

The codebase canonically identifies the iron butterfly as BUTTERFLY
(IronButterflyStrategy.get_strategy_type returns it; the factory registry,
regime mappings, recommendation engine, and API all key on BUTTERFLY).
IRON_BUTTERFLY was referenced only in tests/models/test_scoring_engine.py.

Remove the redundant alias and point that test at the canonical BUTTERFLY.
Enum member count is unchanged (16) since the alias was never a distinct
member. A separate, larger cleanup could rename BUTTERFLY -> IRON_BUTTERFLY
to better reflect the implementation, but that is out of scope here.

Closes cloudtrainerwork#4

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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: StrategyType.BUTTERFLY and IRON_BUTTERFLY share the same enum value, causing silent shadowing

1 participant