RC2_STATE_MIXED
תוכן זה אינו זמין עדיין בשפה שלך.
List elements (or dict values) must all have the same type.
What it means
A class-body list or dict literal mixed element types. Persistent-state lists are typed — list[int], list[float], list[bool], list[str] — and so are dict values. The type is inferred from the first element; a later element that disagrees is rejected up front rather than being coerced.
Why it happens
class Bad(Strategy): trade = Symbol() sizing = FixedCapital()
weird = [1, 2.0] # ❌ int then float
def execute(self): if self.trade.is_flat: self.buy(self.trade)The same rule applies to dict values: {"a": 1, "b": True} mixes int and bool.
How to fix it
Pick one type per collection. If the list is conceptually numeric, write every element as a decimal.
class Good(Strategy): trade = Symbol() sizing = FixedCapital()
prices = [1.0, 2.0] # ✅ all decimal flags = {"a": True, "b": False} # ✅ all bool counts = {"a": 1, "b": 0} # ✅ all int
def execute(self): if self.trade.is_flat: self.buy(self.trade)If two types really do belong side by side, declare two parallel slots:
class Parallel(Strategy): trade = Symbol() sizing = FixedCapital()
ints = [1, 2, 3] # list[int] decimals = [0.5, 1.5, 2.5] # list[decimal]
def execute(self): if self.trade.is_flat: self.buy(self.trade)Related
- Persistent State
RC2_STATE_NESTED— a collection inside a collection is rejected too.RC2_STATE_EMPTY_LIST— a bare[]has no element type to infer at all.