from typing import Any
from typing import Mapping
from typing import Type
import dataclasses


def types_by_field(anything: Any) -> Mapping[str, Type[Any]]:
    """Returns a mapping of an objects fields/attributes to the type of those fields.

    Parameters
    ----------
    object : Any
        Any object.

    Returns
    -------
    Dict[str, type]
        Mapping of an attribute name to its type.
    """
    types_by_field: Mapping[str, Type[type]] = {}
    if dataclasses.is_dataclass(anything):
        types_by_field = {field.name: field.type for field in dataclasses.fields(anything)}
    else:
        types_by_field = {name: type(attribute) for name, attribute in vars(anything).items()}
    return types_by_field