def _check_flag(elems, value):
    """
    Checks that a value is a member of a set of flags.

    Note that we use a top-level function and `partial`. The trouble with lambdas or local
    defs is that they can't be pickled because they're inaccessible to the unpickler.

    If you don't intend to pickle your encoders, though, they're completely fine to use in
    rules.
    """
    return isinstance(value, str) and value in elems
