Skip to content

base_adapter

anymerge.adapters.base_adapter

BaseAdapter

BaseAdapter(model: type[T])

Bases: ABC, Generic[T]

Source code in src/anymerge/adapters/base_adapter.py
def __init__(self, model: type[T]) -> None:
    self.model = model

model instance-attribute

model: type[T] = model

The model type of the adapter.

is_supported_type abstractmethod classmethod

is_supported_type(value: Any) -> TypeGuard[type[T]]

Check if the value is supported by the adapter.

PARAMETER DESCRIPTION
value

The value to check.

TYPE: Any

RETURNS DESCRIPTION
TypeGuard[type[T]]

Whether the value is supported by the adapter.

Source code in src/anymerge/adapters/base_adapter.py
@classmethod
@abc.abstractmethod
def is_supported_type(cls, value: typing.Any) -> typing.TypeGuard[type[T]]:
    """Check if the value is supported by the adapter.

    Args:
        value: The value to check.

    Returns:
        Whether the value is supported by the adapter.
    """

get_fields abstractmethod

get_fields() -> dict[Any, FieldInfo]

Get the fields of the model.

RETURNS DESCRIPTION
dict[Any, FieldInfo]

The fields of the model.

Source code in src/anymerge/adapters/base_adapter.py
@abc.abstractmethod
def get_fields(self) -> dict[typing.Any, FieldInfo]:
    """Get the fields of the model.

    Returns:
        The fields of the model.
    """

get_values abstractmethod

get_values(value: T) -> dict[Any, Any]

Get the values of the instance.

PARAMETER DESCRIPTION
value

The instance to get the values from.

TYPE: T

RETURNS DESCRIPTION
dict[Any, Any]

The values of the instance.

Source code in src/anymerge/adapters/base_adapter.py
@abc.abstractmethod
def get_values(self, value: T) -> dict[typing.Any, typing.Any]:
    """Get the values of the instance.

    Args:
        value: The instance to get the values from.

    Returns:
        The values of the instance.
    """

copy abstractmethod

copy(value: T, *, changes: dict[Any, Any]) -> T

Copy the instance with the changes applied.

PARAMETER DESCRIPTION
value

The instance to copy.

TYPE: T

changes

The changes to apply to the instance.

TYPE: dict[Any, Any]

RETURNS DESCRIPTION
T

The copied instance.

Source code in src/anymerge/adapters/base_adapter.py
@abc.abstractmethod
def copy(self, value: T, *, changes: dict[typing.Any, typing.Any]) -> T:
    """Copy the instance with the changes applied.

    Args:
        value: The instance to copy.
        changes: The changes to apply to the instance.

    Returns:
        The copied instance.
    """

wrap

wrap(value: T) -> WrappedValue[T]

Wrap the value with the adapter.

PARAMETER DESCRIPTION
value

The value to wrap.

TYPE: T

RETURNS DESCRIPTION
WrappedValue[T]

The wrapped value.

Source code in src/anymerge/adapters/base_adapter.py
def wrap(self, value: T) -> WrappedValue[T]:
    """Wrap the value with the adapter.

    Args:
        value: The value to wrap.

    Returns:
        The wrapped value.
    """
    return WrappedValue(value, adapter=self)

WrappedValue

WrappedValue(value: T, *, adapter: BaseAdapter[T])

Bases: Generic[T]

A wrapped value with an adapter.

Source code in src/anymerge/adapters/base_adapter.py
def __init__(self, value: T, *, adapter: BaseAdapter[T]) -> None:
    self.value = value
    self.adapter = adapter

value instance-attribute

value: T = value

The wrapped value.

adapter instance-attribute

adapter: BaseAdapter[T] = adapter

The adapter for the value.