@_check_indexable_cmp
def _get_indexable_cmp(exprnode, indexedcols):
    """Get the indexable variable-constant comparison in `exprnode`.

    A tuple of (variable, operation, constant) is returned if
    `exprnode` is a variable-constant (or constant-variable)
    comparison, and the variable is in `indexedcols`.  A normal
    variable can also be used instead of a constant: a tuple with its
    name will appear instead of its value.

    Otherwise, the values in the tuple are ``None``.
    """

    not_indexable = (None, None, None)
    turncmp = {'lt': 'gt',
               'le': 'ge',
               'eq': 'eq',
               'ge': 'le',
               'gt': 'lt', }

    def get_cmp(var, const, op):
        var_value, const_value = var.value, const.value
        if (var.astType == 'variable' and var_value in indexedcols
           and const.astType in ['constant', 'variable']):
            if const.astType == 'variable':
                const_value = (const_value, )
            return (var_value, op, const_value)
        return None

    def is_indexed_boolean(node):
        return (node.astType == 'variable'
                and node.astKind == 'bool'
                and indexedcols in node.value)

    # Boolean variables are indexable by themselves.
    if is_indexed_boolean(exprnode):
        return (exprnode.value, 'eq', True)
    # And so are negations of boolean variables.
    if exprnode.astType == 'op' and exprnode.value == 'invert':
        child = exprnode.children[0]
        if is_indexed_boolean(child):
            return (child.value, 'eq', False)
        # A negation of an expression will be returned as ``~child``.
        # The indexability of the negated expression will be decided later on.
        if child.astKind == "bool":
            return (child, 'invert', None)

    # Check node type.  Only comparisons are indexable from now on.
    if exprnode.astType != 'op':
        return not_indexable
    cmpop = exprnode.value
    if cmpop not in turncmp:
        return not_indexable

    # Look for a variable-constant comparison in both directions.
    left, right = exprnode.children
    cmp_ = get_cmp(left, right, cmpop)
    if cmp_:
        return cmp_
    cmp_ = get_cmp(right, left, turncmp[cmpop])
    if cmp_:
        return cmp_

    return not_indexable
dataset/ETHPy150Open PyTables/PyTables/tables/conditions.py/_get_indexable_cmp/swapped operands of `in`