docs: def filter_expr(cls_or_alias, **filters):
          """
          forms expressions like [Product.age_from = 5,
                                  Product.subject_ids.in_([1,2])]
          from filters like {'age_from': 5, 'subject_ids__in': [1,2]}
  
          Example 1:
              db.query(Product).filter(
                  *Product.filter_expr(age_from = 5, subject_ids__in=[1, 2]))
  
          Example 2:
              filters = {'age_from': 5, 'subject_ids__in': [1,2]}
              db.query(Product).filter(*Product.filter_expr(**filters))
  
  
          ### About alias ###:
          If we will use alias:
              alias = aliased(Product) # table name will be product_1
          we can't just write query like
              db.query(alias).filter(*Product.filter_expr(age_from=5))
          because it will be compiled to
              SELECT * FROM product_1 WHERE product.age_from=5
          which is wrong: we select from 'product_1' but filter on 'product'
          such filter will not work
  
          We need to obtain
              SELECT * FROM product_1 WHERE product_1.age_from=5
          For such case, we can call filter_expr ON ALIAS:
              alias = aliased(Product)
              db.query(alias).filter(*alias.filter_expr(age_from=5))
  
          Alias realization details:
            * we allow to call this method
              either ON ALIAS (say, alias.filter_expr())
              or on class (Product.filter_expr())
            * when method is called on alias, we need to generate SQL using
              aliased table (say, product_1), but we also need to have a real
              class to call methods on (say, Product.relations)
            * so, we have 'mapper' that holds table name
              and 'cls' that holds real class
  
              when we call this method ON ALIAS, we will have:
                  mapper = <product_1 table>
                  cls = <Product>
              when we call this method ON CLASS, we will simply have:
                  mapper = <Product> (or we could write <Product>.__mapper__.
                                      It doesn't matter because when we call
                                      <Product>.getattr, SA will magically
                                      call <Product>.__mapper__.getattr())
                  cls = <Product>
          """
          if isinstance(cls_or_alias, AliasedClass):
              mapper, cls = cls_or_alias, inspect(cls_or_alias).mapper.class_
          else:
              mapper = cls = cls_or_alias
  
          expressions = []
          valid_attributes = cls.filterable_attributes
          for attr, value in filters.items():
              # if attribute is filtered by method, call this method
              if attr in cls.hybrid_methods:
                  method = getattr(cls, attr)
                  expressions.append(method(value, mapper=mapper))
              # else just add simple condition (== for scalars or IN for lists)
              else:
                  # determine attrbitute name and operator
                  # if they are explicitly set (say, id___between), take them
                  if OPERATOR_SPLITTER in attr:
                      attr_name, op_name = attr.rsplit(OPERATOR_SPLITTER, 1)
                      if op_name not in cls._operators:
                          raise KeyError('Expression `{}` has incorrect '
                                         'operator `{}`'.format(attr, op_name))
                      op = cls._operators[op_name]
                  # assume equality operator for other cases (say, id=1)
                  else:
                      attr_name, op = attr, operators.eq
  
                  if attr_name not in valid_attributes:
                      raise KeyError('Expression `{}` '
                                     'has incorrect attribute `{}`'
                                     .format(attr, attr_name))
  
                  column = getattr(mapper, attr_name)
                  expressions.append(op(column, value))
  
          return expressions