class_docstr: This class abstracts handling of version specifiers.
  
  .. tip::
  
      It is generally not required to instantiate this manually. You should instead
      prefer to work with :class:`SpecifierSet` instead, which can parse
      comma-separated version specifiers (which is what package metadata contains).
docstr: Filter items in the given iterable, that match the specifier.
  
  :param iterable:
      An iterable that can contain version strings and :class:`Version` instances.
      The items in the iterable will be filtered according to the specifier.
  :param prereleases:
      Whether or not to allow prereleases in the returned iterator. If set to
      ``None`` (the default), it will be intelligently decide whether to allow
      prereleases or not (based on the :attr:`prereleases` attribute, and
      whether the only versions matching are prereleases).
  
  This method is smarter than just ``filter(Specifier().contains, [...])``
  because it implements the rule from :pep:`440` that a prerelease item
  SHOULD be accepted if no other versions match the given specifier.
  
  >>> list(Specifier(">=1.2.3").filter(["1.2", "1.3", "1.5a1"]))
  ['1.3']
  >>> list(Specifier(">=1.2.3").filter(["1.2", "1.2.3", "1.3", Version("1.4")]))
  ['1.2.3', '1.3', <Version('1.4')>]
  >>> list(Specifier(">=1.2.3").filter(["1.2", "1.5a1"]))
  ['1.5a1']
  >>> list(Specifier(">=1.2.3").filter(["1.3", "1.5a1"], prereleases=True))
  ['1.3', '1.5a1']
  >>> list(Specifier(">=1.2.3", prereleases=True).filter(["1.3", "1.5a1"]))
  ['1.3', '1.5a1']
docstr_tok: ["Filter","items","in","the","given","iterable",",","that","match","the","specifier",".",":","param","iterable",":","An","iterable","that","can","contain","version","strings","and",":","class",":","`","Version","`","instances",".","The","items","in","the","iterable","will","be","filtered","according","to","the","specifier",".",":","param","prereleases",":","Whether","or","not","to","allow","prereleases","in","the","returned","iterator",".","If","set","to","``","None","``","(","the","default",")",",","it","will","be","intelligently","decide","whether","to","allow","prereleases","or","not","(","based","on","the",":","attr",":","`","prereleases","`","attribute",",","and","whether","the","only","versions","matching","are","prereleases",")",".","This","method","is","smarter","than","just","``","filter","(","Specifier","(",")",".contains",",","[","...","]",")","``","because","it","implements","the","rule","from",":","pep",":","`","440","`","that","a","prerelease","item","SHOULD","be","accepted","if","no","other","versions","match","the","given","specifier",".",">",">",">","list","(","Specifier","(","``",">","=1.2.3","''",")",".filter","(","[","``","1.2","''",",","``","1.3","''",",","``","1.5a1","''","]",")",")","[","'","1.3","'","]",">",">",">","list","(","Specifier","(","``",">","=1.2.3","''",")",".filter","(","[","``","1.2","''",",","``","1.2.3","''",",","``","1.3","''",",","Version","(","``","1.4","''",")","]",")",")","[","'","1.2.3","'",",","'","1.3","'",",","<","Version","(","'","1.4","'",")",">","]",">",">",">","list","(","Specifier","(","``",">","=1.2.3","''",")",".filter","(","[","``","1.2","''",",","``","1.5a1","''","]",")",")","[","'","1.5a1","'","]",">",">",">","list","(","Specifier","(","``",">","=1.2.3","''",")",".filter","(","[","``","1.3","''",",","``","1.5a1","''","]",",","prereleases=True",")",")","[","'","1.3","'",",","'","1.5a1","'","]",">",">",">","list","(","Specifier","(","``",">","=1.2.3","''",",","prereleases=True",")",".filter","(","[","``","1.3","''",",","``","1.5a1","''","]",")",")","[","'","1.3","'",",","'","1.5a1","'","]"]
code: def filter(
      self,
      iterable: Iterable[UnparsedVersionVar],
      prereleases: Optional[bool] = None,
  ) -> Iterator[UnparsedVersionVar]:
      """Filter items in the given iterable, that match the specifier.
  
      :param iterable:
          An iterable that can contain version strings and :class:`Version` instances.
          The items in the iterable will be filtered according to the specifier.
      :param prereleases:
          Whether or not to allow prereleases in the returned iterator. If set to
          ``None`` (the default), it will be intelligently decide whether to allow
          prereleases or not (based on the :attr:`prereleases` attribute, and
          whether the only versions matching are prereleases).
  
      This method is smarter than just ``filter(Specifier().contains, [...])``
      because it implements the rule from :pep:`440` that a prerelease item
      SHOULD be accepted if no other versions match the given specifier.
  
      >>> list(Specifier(">=1.2.3").filter(["1.2", "1.3", "1.5a1"]))
      ['1.3']
      >>> list(Specifier(">=1.2.3").filter(["1.2", "1.2.3", "1.3", Version("1.4")]))
      ['1.2.3', '1.3', <Version('1.4')>]
      >>> list(Specifier(">=1.2.3").filter(["1.2", "1.5a1"]))
      ['1.5a1']
      >>> list(Specifier(">=1.2.3").filter(["1.3", "1.5a1"], prereleases=True))
      ['1.3', '1.5a1']
      >>> list(Specifier(">=1.2.3", prereleases=True).filter(["1.3", "1.5a1"]))
      ['1.3', '1.5a1']
      """
  
      yielded = False
      found_prereleases = []
  
      kw = {
          "prereleases": prereleases
          if prereleases is not None
          else True
      }
  
      # Attempt to iterate over all the values in the iterable and if any of
      # them match, yield them.
      for version in iterable:
          parsed_version = _coerce_version(version)
  
          if self.contains(parsed_version, **kw):
              # If our version is a prerelease, and we were not set to allow
              # prereleases, then we'll store it for later in case nothing
              # else matches this specifier.
              if parsed_version.is_prerelease and not (
                  prereleases or self.prereleases
              ):
                  found_prereleases.append(version)
              # Either this is not a prerelease, or we should have been
              # accepting prereleases from the beginning.
              else:
                  yielded = True
                  yield version
  
      # Now that we've iterated over everything, determine if we've yielded
      # any values, and if we have not and we have any prereleases stored up
      # then we will go ahead and yield the prereleases.
      if not yielded and found_prereleases:
          for version in found_prereleases:
              yield version
  
imports: import abc
  import itertools
  import re
  from typing import Callable, Iterable, Iterator, List, Optional, Set, Tuple, TypeVar, Union
  from .utils import canonicalize_version
  from .version import Version
label_desc: Use image node_id 22 for calling the Specifier obj's underlying member method code with example usage: obj.filter(iterable, prereleases) without return types