import inspect


def _formatannotation(annot):
    """
    Format annotation, properly handling NewType types

    >>> import typing
    >>> _formatannotation(typing.NewType('MyType', str))
    'MyType'
    """
    module = getattr(annot, '__module__', '')
    is_newtype = (getattr(annot, '__qualname__', '').startswith('NewType.') and
                  module == 'typing')
    if is_newtype:
        return annot.__name__
    if module.startswith('nptyping'):  # GH-231
        return repr(annot)
    return inspect.formatannotation(annot)