import enum


def safe_contains(value, container):
    """ Perform "in" containment check, allowing for TypeErrors.

    This is required because in some circumstances ``x in y`` can raise a
    TypeError.  In these cases we make the (reasonable) assumption that the
    value is _not_ contained in the container.
    """
    # Do a LBYL check for Enums, to avoid the DeprecationWarning issued
    # by Python 3.7. Ref: enthought/traits#853.
    if isinstance(container, enum.EnumMeta):
        if not isinstance(value, enum.Enum):
            return False

    try:
        return value in container
    except TypeError:
        return False