def as_str(string, encoding):
    """
    Return the argument `string` converted to a unicode string if it's a
    `bytes` object. Otherwise just return the string.

    If a conversion is necessary, use `encoding`.

    If `string` is neither `str` nor `bytes`, raise a `TypeError`.
    """
    if isinstance(string, bytes):
        return string.decode(encoding)
    elif isinstance(string, str):
        return string
    else:
        raise TypeError("`as_str` argument must be `bytes` or `str`")