class documentation

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).

Method __contains__ Return whether or not the item is contained in this specifier.
Method __eq__ Whether or not the two Specifier-like objects are equal.
Method __hash__ Returns a hash value for this Specifier-like object.
Method __init__ Initialize a Specifier instance.
Method __repr__ A representation of the Specifier that shows all internal state.
Method __str__ A string representation of the Specifier that can be round-tripped.
Method contains Return whether or not the item is contained in this specifier.
Method filter Filter items in the given iterable, that match the specifier.
Method prereleases.setter Setter for :attr:`prereleases`.
Property operator The operator of this specifier.
Property prereleases Whether or not pre-releases as a whole are allowed.
Property version The version of this specifier.
Method _compare_arbitrary Undocumented
Method _compare_compatible Undocumented
Method _compare_equal Undocumented
Method _compare_greater_than Undocumented
Method _compare_greater_than_equal Undocumented
Method _compare_less_than Undocumented
Method _compare_less_than_equal Undocumented
Method _compare_not_equal Undocumented
Method _get_operator Undocumented
Class Variable _operator_regex_str Undocumented
Class Variable _operators Undocumented
Class Variable _regex Undocumented
Class Variable _version_regex_str Undocumented
Instance Variable _prereleases Undocumented
Instance Variable _spec Undocumented
Property _canonical_spec Undocumented
def __contains__(self, item: Union[str, Version]) -> bool: (source)

Return whether or not the item is contained in this specifier. :param item: The item to check for. This is used for the ``in`` operator and behaves the same as :meth:`contains` with no ``prereleases`` argument passed. >>> "1.2.3" in Specifier(">=1.2.3") True >>> Version("1.2.3") in Specifier(">=1.2.3") True >>> "1.0.0" in Specifier(">=1.2.3") False >>> "1.3.0a1" in Specifier(">=1.2.3") False >>> "1.3.0a1" in Specifier(">=1.2.3", prereleases=True) True

def __eq__(self, other: object) -> bool: (source)

Whether or not the two Specifier-like objects are equal. :param other: The other object to check against. The value of :attr:`prereleases` is ignored. >>> Specifier("==1.2.3") == Specifier("== 1.2.3.0") True >>> (Specifier("==1.2.3", prereleases=False) == ... Specifier("==1.2.3", prereleases=True)) True >>> Specifier("==1.2.3") == "==1.2.3" True >>> Specifier("==1.2.3") == Specifier("==1.2.4") False >>> Specifier("==1.2.3") == Specifier("~=1.2.3") False

def __hash__(self) -> int: (source)

Returns a hash value for this Specifier-like object.

def __init__(self, spec: str = '', prereleases: Optional[bool] = None): (source)

Initialize a Specifier instance. :param spec: The string representation of a specifier which will be parsed and normalized before use. :param prereleases: This tells the specifier if it should accept prerelease versions if applicable or not. The default of ``None`` will autodetect it from the given specifiers. :raises InvalidSpecifier: If the given specifier is invalid (i.e. bad syntax).

def __repr__(self) -> str: (source)

A representation of the Specifier that shows all internal state. >>> Specifier('>=1.0.0') <Specifier('>=1.0.0')> >>> Specifier('>=1.0.0', prereleases=False) <Specifier('>=1.0.0', prereleases=False)> >>> Specifier('>=1.0.0', prereleases=True) <Specifier('>=1.0.0', prereleases=True)>

def __str__(self) -> str: (source)

A string representation of the Specifier that can be round-tripped. >>> str(Specifier('>=1.0.0')) '>=1.0.0' >>> str(Specifier('>=1.0.0', prereleases=False)) '>=1.0.0'

def contains(self, item: UnparsedVersion, prereleases: Optional[bool] = None) -> bool: (source)

Return whether or not the item is contained in this specifier. :param item: The item to check for, which can be a version string or a :class:`Version` instance. :param prereleases: Whether or not to match prereleases with this Specifier. If set to ``None`` (the default), it uses :attr:`prereleases` to determine whether or not prereleases are allowed. >>> Specifier(">=1.2.3").contains("1.2.3") True >>> Specifier(">=1.2.3").contains(Version("1.2.3")) True >>> Specifier(">=1.2.3").contains("1.0.0") False >>> Specifier(">=1.2.3").contains("1.3.0a1") False >>> Specifier(">=1.2.3", prereleases=True).contains("1.3.0a1") True >>> Specifier(">=1.2.3").contains("1.3.0a1", prereleases=True) True

def filter(self, iterable: Iterable[UnparsedVersionVar], prereleases: Optional[bool] = None) -> Iterator[UnparsedVersionVar]: (source)

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']

@prereleases.setter
def prereleases(self, value: bool): (source)

Setter for :attr:`prereleases`. :param value: The value to set.

The operator of this specifier. >>> Specifier("==1.2.3").operator '=='

Whether or not pre-releases as a whole are allowed. This can be set to either ``True`` or ``False`` to explicitly enable or disable prereleases or it can be set to ``None`` (the default) to use default semantics.

The version of this specifier. >>> Specifier("==1.2.3").version '1.2.3'

def _compare_arbitrary(self, prospective: Version, spec: str) -> bool: (source)

Undocumented

def _compare_compatible(self, prospective: Version, spec: str) -> bool: (source)

Undocumented

def _compare_equal(self, prospective: Version, spec: str) -> bool: (source)

Undocumented

def _compare_greater_than(self, prospective: Version, spec_str: str) -> bool: (source)

Undocumented

def _compare_greater_than_equal(self, prospective: Version, spec: str) -> bool: (source)

Undocumented

def _compare_less_than(self, prospective: Version, spec_str: str) -> bool: (source)

Undocumented

def _compare_less_than_equal(self, prospective: Version, spec: str) -> bool: (source)

Undocumented

def _compare_not_equal(self, prospective: Version, spec: str) -> bool: (source)

Undocumented

def _get_operator(self, op: str) -> CallableOperator: (source)

Undocumented

_operator_regex_str: str = (source)

Undocumented

_operators: dict[str, str] = (source)

Undocumented

Undocumented

_version_regex_str: str = (source)

Undocumented

_prereleases = (source)

Undocumented

Undocumented

@property
_canonical_spec: Tuple[str, str] = (source)

Undocumented