code: def filter(self, filter_fn=None, desc=None, **kwargs):
          
          if filter_fn is not None and kwargs:
              raise TypeError('Must supply either a filter_fn or attribute filter parameters to filter(), but not both.')
          if filter_fn is None and not kwargs:
              raise TypeError('Must supply one of filter_fn or one or more attribute filter parameters to filter().')
  
          if desc is None:
              if filter_fn is not None:
                  desc = getattr(filter_fn, '__name__', '')
              elif kwargs:
                  desc = u", ".join([u"{}={!r}".format(key, value) for key, value in kwargs.items()])
          desc = u"filter({})".format(desc)
  
          if kwargs:
              def filter_fn(elem):  # pylint: disable=function-redefined, missing-docstring
                  return all(
                      getattr(elem, filter_key) == filter_value
                      for filter_key, filter_value
                      in kwargs.items()
                  )
  
          return self.transform(lambda xs: (x for x in xs if filter_fn(x)), desc=desc)
docs: Return a copy of this query, with some values removed.
  
          Example usages:
  
          .. code:: python
  
              # Returns a query that matches even numbers
              q.filter(filter_fn=lambda x: x % 2)
  
              # Returns a query that matches elements with el.description == "foo"
              q.filter(description="foo")
  
          Keyword Args:
              filter_fn (callable): If specified, a function that accepts one argument (the element)
                      and returns a boolean indicating whether to include that element in the results.
  
              kwargs: Specify attribute values that an element must have to be included in the results.
  
              desc (str): A description of the filter, for use in log messages.
                  Defaults to the name of the filter function or attribute.
  
          Raises:
              TypeError: neither or both of `filter_fn` and `kwargs` are provided.