Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a dataclass for address configuration #75

Open
norswap opened this issue Dec 12, 2023 · 2 comments
Open

Use a dataclass for address configuration #75

norswap opened this issue Dec 12, 2023 · 2 comments
Labels
Milestone

Comments

@norswap
Copy link
Member

norswap commented Dec 12, 2023

Right now, we have a bunch of attributes to configure a single address, e.g.

self.l1_rpc_protocol = "http"
self.l1_rpc_host = "127.0.0.1"
self.l1_rpc_path = ""
self.l1_rpc_port = 8545

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.

@norswap norswap added this to the big-refactor milestone Dec 12, 2023
@Fatal1ty
Copy link

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(...)

@norswap
Copy link
Member Author

norswap commented Dec 17, 2023

Thanks, that's useful to know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants