from typing import Any
from typing import Type


def _eval_arg_type(arg_type, T=Any, arg=None, sig=None):
    """
    Returns a type from a snippet of python source. Should normally be
    something just like 'str' or 'Object'.

      arg_type      the source to be evaluated
      T             the default type
      arg           context of where this type was extracted
      sig           context from where the arg was extracted

    Returns a type or a Type
    """
    try:
        T = eval(arg_type)
    except Exception as e:
        raise ValueError(
            'The type of {} could not be evaluated in {} for {}: {}'.format(
                arg_type, arg, sig, str(e)))
    else:
        if type(T) not in (type, Type):
            raise TypeError(
                '{} is not a valid type in {} for {}'.format(
                    repr(T), arg, sig))
        return T