Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifier Greater than comparison returns incorrect result for a version with dev+local parts #810

Open
rng-zz opened this issue Jun 4, 2024 · 0 comments

Comments

@rng-zz
Copy link

rng-zz commented Jun 4, 2024

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 local segment
  • the compared version differs in its dev segment.

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 #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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants