from typing import TypeVar
from typing import Any
from typing import Union


def _get_mapping_key_and_value_annotations(attr_spec):
    """
    Get the annotations of keys and values for mapping method signatures.
    """
    key_type = (
        attr_spec.type.__args__[0]
        if hasattr(attr_spec.type, "__args__")
        and not isinstance(attr_spec.type.__args__[0], TypeVar)
        else Any
    )
    value_type = attr_spec.item_type
    if attr_spec.item_spec_key_type:
        value_type = Union[
            attr_spec.item_spec_key_type,
            value_type,
        ]
    return key_type, value_type