INNER CODE UNIT · Python
init_dynamic_model
DogsTailFarmer/martin-binance · martin_binance/backup.py:328
def init_dynamic_model(strategy_instance, attributes_to_backup: List[str]):
"""
Builds the Pydantic model 'StateResponse' on-the-fly at startup.
Uses an elegant unified pipeline combining AST-parsing and runtime inference.
Successfully handles complex nested structures like Dict[...] and Tuple[...] without type drops.
"""
base_fields = {}
ast_annotations = get_init_self_annotations(strategy_instance)
eval_context = {
'Optional': Optional, 'Dict': Dict, 'Tuple': Tuple, 'List': List, 'Any': Any, 'Union': Union,
'datetime': datetime, 'DecimalStr': DecimalStr, 'Decimal': Decimal,
'int': int, 'float': float, 'str': str, 'bool': bool
}
for attr_name in attributes_to_backup:
default_value = getattr(strategy_instance, attr_name, None)
hint_type = None