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 equivalence check does not consider version equivalence #282

Closed
uranusjr opened this issue Mar 25, 2020 · 1 comment · Fixed by #283
Closed

Specifier equivalence check does not consider version equivalence #282

uranusjr opened this issue Mar 25, 2020 · 1 comment · Fixed by #283

Comments

@uranusjr
Copy link
Member

@uranusjr uranusjr commented Mar 25, 2020

Orginally reported as pypa/pip#7900.

Currently the specifier equivalence check compares the contained version as a string. packaging.version.parse should be used instead to ensure equivalent version strings are considered equal.

Minimal reproduction:

>>> from packaging.specifiers import SpecifierSet
>>> SpecifierSet("==2.8.0") == SpecifierSet("==2.8.0")
True
>>> SpecifierSet("==2.8.0") == SpecifierSet("==2.8")
False
@di
Copy link
Sponsor Member

@di di commented Mar 25, 2020

The issue is that the specifiers are not considered equal:

def __eq__(self, other):
# type: (object) -> bool
if isinstance(other, string_types):
try:
other = self.__class__(str(other))
except InvalidSpecifier:
return NotImplemented
elif not isinstance(other, self.__class__):
return NotImplemented
return self._spec == other._spec

>>> from packaging.specifiers import Specifier
>>> Specifier('==2.8.0') == Specifier('==2.8')
False
>>> Specifier('==2.8.0') == Specifier('==2.8.0')
True
>>> Specifier('==2.8.0')._spec
('==', '2.8.0')
>>> Specifier('==2.8')._spec
('==', '2.8')

We should canonicalize the version when comparing them, I created #283 to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants