Skip to content

Instantly share code, notes, and snippets.

@gauthamchettiar
gauthamchettiar / event-dict.py
Created June 7, 2025 14:30
python type declaration : event as dict
# dict, naive validation handling
item_event = {"type": "ITEM", "action": "EQUIP", "data": {"item": "SHORT_SWORD", "at": "LEFT_HAND", "on": "SWORDMASTER_1"}}
stat_event = { "type": "STAT", "action": "STAT_CHANGE", "data": { "stat": "EXPERIENCE", "change": { "from": 10, "to": 11 }, "on":"SWORDMASTER_1"}}
action_event = {"type": "ACTION", "action": "ATTACK", "data": {"from": "SWORDMASTER_1", "to": "ENEMY_1", "type": "SLASH" }}
def validate_event(event):
if not isinstance(event, dict):
raise TypeError("Event must be a dictionary.")
# Format Specification Mini-Language (Quick Reference)
import datetime
integer = 5
negative_integer = -5
decimal = 6.9
negative_decimal = -6.9
string = 'hi'
cost_float = 1299.99
cost_integer = 150000