Skip to content

Base

_base

BaseModel

Base model for all models

to_dict

to_dict() -> dict[str, Any]

Convert the model to a dict

Returns:

Type Description
Dict[str, Any]

The model as a dict.

Source code in pokelance/models/_base.py
def to_dict(self) -> dict[str, t.Any]:
    """Convert the model to a dict

    Returns
    -------
    t.Dict[str, Any]
        The model as a dict.
    """
    return attrs.asdict(
        self, filter=attrs.filters.exclude(attrs.fields(BaseModel).raw), value_serializer=_serializer
    )

from_payload classmethod

from_payload(payload: dict[str, Any]) -> Self

Create a model from a payload

Parameters:

Name Type Description Default
payload dict[str, Any]

The payload to create the model from.

required

Returns:

Type Description
BaseModel

The model created from the payload.

Source code in pokelance/models/_base.py
@classmethod
def from_payload(cls, payload: dict[str, t.Any]) -> Self:
    """Create a model from a payload

    Parameters
    ----------
    payload: t.Dict[str, Any]
        The payload to create the model from.

    Returns
    -------
    BaseModel
        The model created from the payload.
    """
    return cls(raw=payload)

Comments