For purposes of prefix matching, the pre-release segment is considered to have an implied preceding ., so given the version 1.1a1, the following clauses would match or not as shown:
[...]
== 1.1.* # Same prefix, so 1.1a1 matches clause
However, when I test this example with the relevant tools from packaging, the outcome is different than the above:
$ pip install --upgrade packaging
[...]
Successfully installed packaging-23.1
[...]
$ python
Python 3.9.9 (main, Dec 22 2021, 01:10:49)
[...]
>>> from packaging.specifiers import SpecifierSet
>>> from packaging.version import Version
>>> s = SpecifierSet('== 1.1.*')
>>> v = Version('1.1a1')
>>> s.contains(v)
False
Is PEP-440 or packaging right? Or, maybe, what am I missing?
Am I correct, that the prereleases=True behavior is used – in practice, by such tools as pip and setuptools – when there is no available non-prerelease version or the user explicitly demands on using prereleases?
I don’t recall the details of what pip does offhand (feel free to go and check the code yourself if you want ) but how tools should handle prereleases is covered in PEP 440.
I agree it is not, and please note that this example is from the PEP itself.
What I am trying to say is that the fragment of the PEP quoted by me (i.e., the following bullet point in the Examples section: == 3.1.*: any version that starts with 3.1. Equivalent to the ~=3.1.0 compatible release clause.) – seems to contradict the specification in earlier parts of the document.