packaging
packaging copied to clipboard
`Specifier` Greater than comparison returns incorrect result for a version with dev+local parts
When a using a Specifier with a > comparison, comparing returns an incorrect result for the following situation:
- the base version of the specifier and compared version are equal
- the compared version includes a
localsegment - the compared version differs in its
devsegment.
My understanding from PEP440 is that the entire public portion of the version (including the dev segment) should be included in the comparison? I think this is due to this line: https://github.com/pypa/packaging/blob/main/src/packaging/specifiers.py#L489 where it should instead be:
if prospective.local is not None:
if Version(prospective.public) == Version(spec.public):
return False
This is related, but not exactly the same as https://github.com/pypa/packaging/issues/519 (as this issue is specifically about comparing two dev versions).
Example:
>>> from pip._vendor.packaging.specifiers import Specifier
>>> spec = Specifier(">4.1.0a2.dev1234")
# Correct comparisons with no local segment
>>> spec.contains("4.1.0a2.dev1234", prereleases=True)
False
>>> spec.contains("4.1.0a2.dev1235", prereleases=True)
True
# Incorrect comparison when including a local segment
>>> spec.contains("4.1.0a2.dev1234+local", prereleases=True)
False
>>> spec.contains("4.1.0a2.dev1235+local", prereleases=True)
False