Skip to content

typed_kwargs

dandy.core.typing.typed_kwargs

TypedKwargs

Bases: UserDict

Source code in dandy/core/typing/typed_kwargs.py
def __init__(
        self,
        data: TypedKwargsDict | dict[Any, Any],
):
    super().__init__(data)

__contains__

Source code in dandy/core/typing/typed_kwargs.py
def __contains__(self, item: Self) -> bool:
    if not isinstance(item, TypedKwargs):
        message = f'Cannot compare TypedKwargs with {type(item)}. TypedKwargs can only be compared with TypedKwargs.'
        raise DandyCriticalError(message)

    if not self._is_valid_sub_set_typed_kwargs(item):
        return False

    for key in item:
        first_type = self[key][0]
        second_type = item[key][0]

        if isinstance(first_type, str):
            first_type = resolve_type_from_registry(
                type_str=first_type
            )

        if isinstance(second_type, str):
            second_type = resolve_type_from_registry(
                type_str=second_type
            )

        if first_type is not second_type:
            return False

    return True