def typename(value):
    """
    Return the name of a type. Idiosyncratic formatting to show in order to
    provide the right information, but in the least verbose way possible. E.g.
    where Python would format `<type 'int'>` or `class '__main__.CName'>` or
    `<class 'module.submod.CName'>`, this function would return `<int>`,
    `<CName>`, and `<CName>` respectively. If a neat name cannot be returned
    directly, the default Python type formatting is invoked, then the string
    result hacked apart.
    """
    type_ = type(value)
    try:
        return '<{0}>'.format(type_.__name__)
    except AttributeError:
        rawname = '{0!r}'.format(type_)
        return rawname[rawname.index("'") + 1:rawname.rindex("'")]
