Open norswap opened 11 months ago
I would recommend to take a look at mashumaro (which has TOML support out of the box) or another library. It will take a lot of manual work and error handling away from you.
In your case, it might look something like this:
from dataclasses import dataclass
from enum import Enum
from ipaddress import IPv4Address
from mashumaro.mixins.toml import DataClassTOMLMixin
class L1RPCProtocol(Enum):
HTTP = "http"
@dataclass
class Config(DataClassTOMLMixin):
l1_rpc_protocol: L1RPCProtocol
l1_rpc_host: IPv4Address
l1_rpc_path: str
l1_rpc_port: int
config = Config.from_toml(...)
Thanks, that's useful to know!
Right now, we have a bunch of attributes to configure a single address, e.g.
It would be good to be able to replace this with a single data class. The key question is if we can get the TOML parser to automatically parse this data structure.