Skip to content

base_settings

A base class to store common logic needed from settings classes.

BaseSettings dataclass

Bases: ABC

A base class to store common logic needed from settings classes.

Dataclasses like this help with type checking and setting defaults. They also make it really easy to add new settings.

Methods:

Name Description
__post_init__

Optionally validates the input settings after the dataclass is initialized.

validate

Validates the input settings.

__str__

Returns a string representation of the settings.

__repr__

Returns a string representation of the settings.

Source code in src/mada_tools/shared/base_settings.py
@dataclass
class BaseSettings(ABC):
    """
    A base class to store common logic needed from settings classes.

    Dataclasses like this help with type checking and setting defaults.
    They also make it really easy to add new settings.

    Methods:
        __post_init__: Optionally validates the input settings after the dataclass is initialized.
        validate: Validates the input settings.
        __str__: Returns a string representation of the settings.
        __repr__: Returns a string representation of the settings.
    """

    def __post_init__(self):
        """
        Optionally validates the input settings after the dataclass is initialized.
        """
        self.validate()

    def validate(self):
        """
        Validates the input settings.

        This method can be overridden by subclasses to provide specific validation logic.
        """
        pass

    def __str__(self):
        """
        Returns a string representation of the settings.
        """
        result = [f"{self.__class__.__name__} settings"]
        for key, value in self.__dict__.items():
            result.append(f"  - {key}: {value}")
        return "\n".join(result) + "\n"

    def __repr__(self):
        """
        Returns a string representation of the settings.
        """
        return f"{self.__class__.__name__}({self.__dict__})"

__post_init__()

Optionally validates the input settings after the dataclass is initialized.

Source code in src/mada_tools/shared/base_settings.py
def __post_init__(self):
    """
    Optionally validates the input settings after the dataclass is initialized.
    """
    self.validate()

__repr__()

Returns a string representation of the settings.

Source code in src/mada_tools/shared/base_settings.py
def __repr__(self):
    """
    Returns a string representation of the settings.
    """
    return f"{self.__class__.__name__}({self.__dict__})"

__str__()

Returns a string representation of the settings.

Source code in src/mada_tools/shared/base_settings.py
def __str__(self):
    """
    Returns a string representation of the settings.
    """
    result = [f"{self.__class__.__name__} settings"]
    for key, value in self.__dict__.items():
        result.append(f"  - {key}: {value}")
    return "\n".join(result) + "\n"

validate()

Validates the input settings.

This method can be overridden by subclasses to provide specific validation logic.

Source code in src/mada_tools/shared/base_settings.py
def validate(self):
    """
    Validates the input settings.

    This method can be overridden by subclasses to provide specific validation logic.
    """
    pass