def castable(value, typename):
    """Can value be cast as type typename without throwing an exception?"""
    try:
        typename(value)
        return True
    except Exception:
        return False
