Skip to content

config

dev_tool.event.handler.config

log = logging.getLogger(__name__) module-attribute

ConfigEventHandler

A handler class for configuration change events.

This class manages callbacks for configuration changes and executes them when corresponding events are received.

The constructor for the ConfigEventHandler class.

Initializes empty callback lists for each configuration event type.

Source code in dev_tool/event/handler/config.py
def __init__(self) -> None:
    """
    The constructor for the ConfigEventHandler class.

    Initializes empty callback lists for each configuration event type.
    """

    self._callbacks: dict[AppEventType, list[Callable[[], None]]] = {
        AppEventType.CONFIG_ENV_CHANGED: [],
        AppEventType.CONFIG_PYPROJECT_CHANGED: [],
    }

handle

A method that handles configuration change events.

Parameters:

  • event (Event) –

    The event object to handle.

Source code in dev_tool/event/handler/config.py
def handle(self, event: Event) -> None:
    """
    A method that handles configuration change events.

    :param event: The event object to handle.
    """

    event_type = cast('AppEventType', event.type)
    callbacks = self._callbacks.get(event_type, [])

    for callback in callbacks:
        try:
            callback()
        except Exception:
            log.exception(f'Config event callback failed for {event.type}')

register_callback

A method that registers a callback for a configuration event.

Parameters:

  • event_type (AppEventType) –

    The event type to listen for.

  • callback (Callable[[], None]) –

    The callback function to execute.

Source code in dev_tool/event/handler/config.py
def register_callback(self, event_type: AppEventType, callback: Callable[[], None]) -> None:
    """
    A method that registers a callback for a configuration event.

    :param event_type: The event type to listen for.
    :param callback: The callback function to execute.
    """

    if event_type in self._callbacks:
        self._callbacks[event_type].append(callback)

unregister_callback

A method that unregisters a callback for a configuration event.

Parameters:

  • event_type (AppEventType) –

    The event type to stop listening for.

  • callback (Callable[[], None]) –

    The callback function to remove.

Source code in dev_tool/event/handler/config.py
def unregister_callback(self, event_type: AppEventType, callback: Callable[[], None]) -> None:
    """
    A method that unregisters a callback for a configuration event.

    :param event_type: The event type to stop listening for.
    :param callback: The callback function to remove.
    """

    if event_type in self._callbacks and callback in self._callbacks[event_type]:
        self._callbacks[event_type].remove(callback)

get_event_type staticmethod

A method that returns the event types this handler processes.

Returns:

Source code in dev_tool/event/handler/config.py
@staticmethod
def get_event_type() -> list[AppEventType]:
    """
    A method that returns the event types this handler processes.

    :return: A list of event types.
    """

    return [
        AppEventType.CONFIG_ENV_CHANGED,
        AppEventType.CONFIG_PYPROJECT_CHANGED,
    ]