from typing import Type
from typing import Hashable


def _lookup(key: str, typ: Type, *args, **kwargs) -> Hashable:
    """
    Gets the value of the given key in args, defaulting to the first positional.

    :param key: key to find value of in args.
    :param typ: type that dispatch is being perform on.
    :param args: positional args.
    :param kwargs: keyword args.
    :return: value of the key in the given args.
    """
    if key in kwargs:
        value = kwargs[key]
    else:
        try:
            if typ.__qualname__.endswith('.__new__'):
                value = args[1]
            else:
                value = args[0]
        except IndexError:
            raise TypeError(f'missing dispatch parameter {key!r} on {typ.__name__}')

    return value