Base_binder

This module contains functionality related to the the base_binder module for common.bootstrap.

Base_binder

BaseBinder

Bases: ABC

Base class for binders.

Attributes:
  • configuration

    Configuration object

  • binder

    Injector binder

Source code in src/common/bootstrap/base_binder.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class BaseBinder(ABC):
    """Base class for binders.

    Attributes:
        configuration: Configuration object
        binder: Injector binder
    """

    def __init__(self, configuration: "Configuration", binder: Binder) -> None:
        """Initialize the BaseBinder.

        Args:
            configuration: Configuration object
            binder: Injector binder
        """
        self.configuration = configuration
        self.binder = binder

    @abstractmethod
    def bind(self) -> None:
        """Bind components to the injector based on the configuration."""
        pass

    def _get_bind(self, key: Any) -> Any:
        """Get the bind function for the given key.

        Args:
            key: Key to bind

        Returns:
            Any: Bind function
        """
        return lambda: self.binder.injector.get(key)

    def _pydantic_config_is_equal(self, a: BaseModel, b: BaseModel) -> bool:
        """Check if two Pydantic configuration objects are equal.

        Args:
            a: Pydantic configuration object
            b: Pydantic configuration object

        Returns:
            bool: True if the objects are equal, False otherwise"""
        return a.model_dump() == b.model_dump()

__init__(configuration, binder)

Initialize the BaseBinder.

Parameters:
  • configuration (Configuration) –

    Configuration object

  • binder (Binder) –

    Injector binder

Source code in src/common/bootstrap/base_binder.py
28
29
30
31
32
33
34
35
36
def __init__(self, configuration: "Configuration", binder: Binder) -> None:
    """Initialize the BaseBinder.

    Args:
        configuration: Configuration object
        binder: Injector binder
    """
    self.configuration = configuration
    self.binder = binder

_get_bind(key)

Get the bind function for the given key.

Parameters:
  • key (Any) –

    Key to bind

Returns:
  • Any( Any ) –

    Bind function

Source code in src/common/bootstrap/base_binder.py
43
44
45
46
47
48
49
50
51
52
def _get_bind(self, key: Any) -> Any:
    """Get the bind function for the given key.

    Args:
        key: Key to bind

    Returns:
        Any: Bind function
    """
    return lambda: self.binder.injector.get(key)

_pydantic_config_is_equal(a, b)

Check if two Pydantic configuration objects are equal.

Parameters:
  • a (BaseModel) –

    Pydantic configuration object

  • b (BaseModel) –

    Pydantic configuration object

Returns:
  • bool( bool ) –

    True if the objects are equal, False otherwise

Source code in src/common/bootstrap/base_binder.py
54
55
56
57
58
59
60
61
62
63
def _pydantic_config_is_equal(self, a: BaseModel, b: BaseModel) -> bool:
    """Check if two Pydantic configuration objects are equal.

    Args:
        a: Pydantic configuration object
        b: Pydantic configuration object

    Returns:
        bool: True if the objects are equal, False otherwise"""
    return a.model_dump() == b.model_dump()

bind() abstractmethod

Bind components to the injector based on the configuration.

Source code in src/common/bootstrap/base_binder.py
38
39
40
41
@abstractmethod
def bind(self) -> None:
    """Bind components to the injector based on the configuration."""
    pass

BaseBoundKey

Bases: ABC

Base class for bound keys. Used to bind and extract instances from the injector.

Source code in src/common/bootstrap/base_binder.py
11
12
13
14
15
16
17
class BaseBoundKey(ABC):
    """Base class for bound keys. Used to bind and extract instances from the injector."""

    @abstractmethod
    def _(self):
        """Empty function to avoid unintended initialization."""
        pass

_() abstractmethod

Empty function to avoid unintended initialization.

Source code in src/common/bootstrap/base_binder.py
14
15
16
17
@abstractmethod
def _(self):
    """Empty function to avoid unintended initialization."""
    pass