

def filter(self, *args, **kwargs):
    dq_node = Node()
    if args:
        dq_node &= reduce(operator.and_, [a.clone() for a in args])
    if kwargs:
        dq_node &= DQ(**kwargs)
    q = deque([dq_node])
    dq_joins = set()
    while q:
        curr = q.popleft()
        if (not isinstance(curr, Expression)):
            continue
        for (side, piece) in (('lhs', curr.lhs), ('rhs', curr.rhs)):
            if isinstance(piece, DQ):
                (query, joins) = self.convert_dict_to_node(piece.query)
                dq_joins.update(joins)
                expression = reduce(operator.and_, query)
                expression._negated = piece._negated
                expression._alias = piece._alias
                setattr(side, side, expression)
            else:
                q.append(piece)
    dq_node = dq_node.rhs
    query = self.clone()
    for field in dq_joins:
        if isinstance(field, ForeignKeyField):
            (lm, rm) = (field.model_class, field.rel_model)
            field_obj = field
        elif isinstance(field, ReverseRelationDescriptor):
            (lm, rm) = (field.field.rel_model, field.rel_model)
            field_obj = field.field
        query = query.ensure_join(lm, rm, field_obj)
    return query.where(dq_node)

dataset/ETHPy150Open coleifer/peewee/peewee.py Query.filter/VarMisuse@195/235 `curr`->`side`