Return whether or not the item is contained in this SpecifierSet. :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 SpecifierSet. If
(
self,
item: UnparsedVersion,
prereleases: Optional[bool] = None,
installed: Optional[bool] = None,
)
| 894 | return self.contains(item) |
| 895 | |
| 896 | def contains( |
| 897 | self, |
| 898 | item: UnparsedVersion, |
| 899 | prereleases: Optional[bool] = None, |
| 900 | installed: Optional[bool] = None, |
| 901 | ) -> bool: |
| 902 | """Return whether or not the item is contained in this SpecifierSet. |
| 903 | |
| 904 | :param item: |
| 905 | The item to check for, which can be a version string or a |
| 906 | :class:`Version` instance. |
| 907 | :param prereleases: |
| 908 | Whether or not to match prereleases with this SpecifierSet. If set to |
| 909 | ``None`` (the default), it uses :attr:`prereleases` to determine |
| 910 | whether or not prereleases are allowed. |
| 911 | |
| 912 | >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.2.3") |
| 913 | True |
| 914 | >>> SpecifierSet(">=1.0.0,!=1.0.1").contains(Version("1.2.3")) |
| 915 | True |
| 916 | >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.0.1") |
| 917 | False |
| 918 | >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1") |
| 919 | False |
| 920 | >>> SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True).contains("1.3.0a1") |
| 921 | True |
| 922 | >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1", prereleases=True) |
| 923 | True |
| 924 | """ |
| 925 | # Ensure that our item is a Version instance. |
| 926 | if not isinstance(item, Version): |
| 927 | item = Version(item) |
| 928 | |
| 929 | # Determine if we're forcing a prerelease or not, if we're not forcing |
| 930 | # one for this particular filter call, then we'll use whatever the |
| 931 | # SpecifierSet thinks for whether or not we should support prereleases. |
| 932 | if prereleases is None: |
| 933 | prereleases = self.prereleases |
| 934 | |
| 935 | # We can determine if we're going to allow pre-releases by looking to |
| 936 | # see if any of the underlying items supports them. If none of them do |
| 937 | # and this item is a pre-release then we do not allow it and we can |
| 938 | # short circuit that here. |
| 939 | # Note: This means that 1.0.dev1 would not be contained in something |
| 940 | # like >=1.0.devabc however it would be in >=1.0.debabc,>0.0.dev0 |
| 941 | if not prereleases and item.is_prerelease: |
| 942 | return False |
| 943 | |
| 944 | if installed and item.is_prerelease: |
| 945 | item = Version(item.base_version) |
| 946 | |
| 947 | # We simply dispatch to the underlying specs here to make sure that the |
| 948 | # given version is contained within all of them. |
| 949 | # Note: This use of all() here means that an empty set of specifiers |
| 950 | # will always return True, this is an explicit design decision. |
| 951 | return all(s.contains(item, prereleases=prereleases) for s in self._specs) |
| 952 | |
| 953 | def filter( |
no test coverage detected