From 0cc2e9de058afe6ad55b92a882e4decf615da4a4 Mon Sep 17 00:00:00 2001 From: rahul Date: Wed, 16 Oct 2024 04:40:08 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20perf:=20Optimize=20config=20wrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/env.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/config/env.py b/src/config/env.py index d153d2eb33..68e5236a0f 100644 --- a/src/config/env.py +++ b/src/config/env.py @@ -54,15 +54,11 @@ class Config(BaseModel): remote_nodes: List[RemoteNode] -class EnvConfig: - """ - Loads and validates environment configuration from `env.yaml`. - - Attributes: - - config (Config): An instance of the Config class containing validated settings. +class EnvConfig(Config): + """Loads and validates environment configuration from `env.yaml`. - Raises: - - ValueError: If the configuration is invalid. + This is a wrapper class for the Config model. It reads a config file + from disk into a Config model and then exposes it. """ def __init__(self): @@ -75,15 +71,11 @@ def __init__(self): with ENV_PATH.open("r") as file: config_data = yaml.safe_load(file) try: - self.config = Config(**config_data) # Validate and parse with Pydantic + # Validate and parse with Pydantic + super().__init__(**config_data) except ValidationError as e: raise ValueError(f"Invalid configuration: {e}") - @property - def remote_nodes(self): - """Returns the list of remote nodes from the configuration.""" - return self.config.remote_nodes - # The default configuration represented as a Config model. DEFAULT_CONFIG = Config(