def equals_or_in(item, collection):
    """
    Return true if the item is the collection, or is in the collection.
    Guard against possible TypeError exceptions (ie, testing if `int` is
    in `str` can raise this).
    """
    if item == collection:
        return True
    if hasattr(collection, '__contains__'):
        try:
            if item in collection:
                return True
        except TypeError:
            pass
    return False
