contains method
contains
python docstring
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
python source
def contains(
self, item: UnparsedVersion, prereleases: Optional[bool] = None
) -> bool:
"""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
"""
# Determine if prereleases are to be allowed or not.
if prereleases is None:
prereleases = self.prereleases
# Normalize item to a Version, this allows us to have a shortcut for
# "2.0" in Specifier(">=2")
normalized_item = _coerce_version(item)
# Determine if we should be supporting prereleases in this specifier
# or not, if we do not support prereleases than we can short circuit
# logic if this version is a prereleases.
if normalized_item.is_prerelease and not prereleases:
return False
# Actually do the comparison to determine if this item is contained
# within this Specifier or not.
operator_callable: CallableOperator = self._get_operator(self.operator)
return operator_callable(normalized_item, self.version)
Implementation
bool contains({
required Object? item,
Object? prereleases,
}) =>
getFunction("contains").call(
<Object?>[
item,
prereleases,
],
kwargs: <String, Object?>{},
);