reload_config_base.py
Overview
reload_config_base.py defines a foundational class ReloadConfigBase designed to serve as a base for configuration management within the InfiniFlow project. This class provides utility class methods to access configuration parameters declared as class attributes in subclasses, allowing retrieval of all configurations or specific ones by name.
The main functionality includes:
Enumerating all non-callable, non-private class attributes as configuration entries.
Fetching individual configuration values by their attribute name.
This base class facilitates a consistent and straightforward interface for managing reloadable configurations across different components or modules in the system.
Class Details
Class: ReloadConfigBase
ReloadConfigBase is intended as a superclass for configuration containers. It does not define any configuration parameters itself but provides two key class methods for accessing subclass configurations.
Methods
get_all()
@classmethod
def get_all(cls) -> dict:
Returns a dictionary of all configuration entries defined as class attributes on the subclass.
Parameters:
cls: The class object (implicit for classmethod).
Returns:
dict: A dictionary where keys are the names of configuration parameters (class attribute names) and values are their corresponding values.
Details:
Filters out:
Callable attributes (methods or functions).
Attributes starting with double underscores (
_) or a single underscore (), which are conventionally private or special.
Only includes public, non-callable class-level attributes.
Usage Example:
class MyConfig(ReloadConfigBase): timeout = 30 max_retries = 5 _private_attr = "hidden" def some_method(self): pass configs = MyConfig.get_all() print(configs) # Output: {'timeout': 30, 'max_retries': 5}
get(config_name)
@classmethod
def get(cls, config_name: str):
Fetches the value of a specific configuration parameter by name.
Parameters:
config_name(str): The name of the configuration parameter to retrieve.
Returns:
The value of the configuration parameter if it exists.
Noneif the parameter does not exist on the class.
Details:
Uses
hasattrto check for the attribute.Does not check if the attribute is callable or private; returns it if present.
Usage Example:
class MyConfig(ReloadConfigBase): timeout = 30 timeout_value = MyConfig.get("timeout") print(timeout_value) # Output: 30 missing_value = MyConfig.get("nonexistent") print(missing_value) # Output: None
Implementation Details and Algorithms
The class relies on Python's built-in
dictattribute of the class object to inspect all attributes declared on the class.Attributes that are callable or start with underscores are excluded from the
get_allmethod to provide a clean dictionary of configuration parameters.The methods are class methods, which means they operate on the class itself rather than instances. This design suits classes intended as static containers of configuration values.
No configuration validation or type enforcement is performed; the class acts purely as a container and accessor.
Interaction with Other Parts of the System
ReloadConfigBaseis designed to be subclassed by other configuration classes within the InfiniFlow system.Other modules or components that require configuration values can use subclasses of
ReloadConfigBaseto retrieve configuration parameters dynamically.This approach supports a reloadable or modular configuration system where different components can extend the base class with their own parameters.
The class does not handle persistence, loading from files, or dynamic updates; it focuses solely on structured access to in-class static configurations.
Diagram: Class Structure of ReloadConfigBase
classDiagram
class ReloadConfigBase {
<<abstract>>
+get_all() dict
+get(config_name: str)
}
ReloadConfigBaseis an abstract-style base class (although not enforced by inheritance) that provides two public class methods.No instance methods or properties are defined.
Intended to be subclassed for concrete configuration definitions.
Summary
reload_config_base.py provides a lightweight base class for configuration management using class attributes. It simplifies retrieving all or specific configuration values defined in subclasses while filtering out private or callable attributes. This utility supports clean configuration access patterns across the InfiniFlow project components.