cast bytes or str to str

def cast_str(s, encoding='utf8', errors='strict'):
    """cast bytes or str to str"""
    if isinstance(s, bytes):
        return s.decode(encoding, errors)
    elif isinstance(s, str):
        return s
    else:
        raise TypeError("Expected unicode or bytes, got %r" % s)