RC2_STATE_EMPTY_DICT
A bare
{}literal has no value type to infer.
What it means
A class-body dict declared as name = {} carries no value-type information. RaamCode can’t tell whether the values are ints, decimals, bools, or strings — and the slot has to be typed before the first bar runs.
Why it happens
class Bad(Strategy): trade = Symbol() sizing = FixedCapital()
empty = {} # ❌ — what's the value type?
def execute(self): if self.trade.is_flat: self.buy(self.trade)How to fix it
Declare one entry to pin the value type, then fill or clear it in execute().
class Good(Strategy): trade = Symbol() sizing = FixedCapital()
stops = {"_": 0.0} # ✅ pins the value type as decimal
def execute(self): if self.bar_count == 1: self.stops["entry"] = self.trade.close if self.trade.is_flat: self.buy(self.trade)Or, when the keys are known up front, declare them with their initial values:
class Prefilled(Strategy): trade = Symbol() sizing = FixedCapital()
counts = {"up": 0, "down": 0, "doji": 0} # ✅ pre-populated
def execute(self): if self.trade.close > self.trade.open: self.counts["up"] += 1 if self.trade.is_flat: self.buy(self.trade)Why we don’t allow bare {}
Same reason as RC2_STATE_EMPTY_LIST — the value type is pinned by the literal you declare, and an empty literal gives it nothing to bind to. The single-entry idiom is the smallest thing that removes the ambiguity.
Related
- Persistent State
RC2_STATE_EMPTY_LIST— the same rule for lists.RC2_STATE_DICT_KEY— dict keys must be string literals.