import typing
import ast


def getattribute(
    entity_name: str, attributes: typing.List[str]
) -> typing.Union[ast.Name, ast.Attribute]:
    """Get object attribute.

    Generates following code:
        getattribute(entity_name, [attribute]) -> `entity_name.attribute`
        getattribute(entity_name, [attribute, get]) -> `entity_name.attribute.get`

    :param entity_name: dictionary variable name
    :param attributes: list of attributes names
    """
    value: typing.Union[ast.Name, ast.Attribute] = ast.Name(
        id=entity_name, ctx=ast.Load()
    )
    for attribute in attributes:
        value = ast.Attribute(
            value=value,
            attr=attribute,
            ctx=ast.Load(),
        )
    return value