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

Padded Calver is breaking comparisons #583

Closed
shughes-uk opened this issue Aug 11, 2022 · 3 comments · Fixed by #561
Closed

Padded Calver is breaking comparisons #583

shughes-uk opened this issue Aug 11, 2022 · 3 comments · Fixed by #561

Comments

@shughes-uk
Copy link

shughes-uk commented Aug 11, 2022

Fairly easy to recreate

from packaging import specifiers
# this returns False
specifiers.SpecifierSet("~=2022.01.01").contains("2022.01.01")

Seems when passing the raw string the parse function is reducing the comparison version to 2022.1.1 which never matches ~=2022.01.01.

My workaround is to always parse the version and use version.base_version for the specifier

from packaging import specifiers, version

spec_version = version.parse("2022.01.01")
specifiers.SpecifierSet(f"~={spec_version.base_version}").contains("2022.01.01")
@pradyunsg
Copy link
Member

Can you reproduce this with the current main branch of this repository?

pip install git+https://github.com/pypa/packaging

@shughes-uk
Copy link
Author

shughes-uk commented Aug 11, 2022

Yup

In [3]: from packaging import specifiers
   ...: 
   ...: # this returns False
   ...: specifiers.SpecifierSet("~=2022.01.01").contains("2022.01.01")
   ...: 
Out[3]: False

In [4]: import packaging

In [5]: packaging.__version__
Out[5]: '21.4.dev0'

Python 3.8.13 on arm64 macos

@uranusjr
Copy link
Member

I believe this is the same as #561; ~= {version} simply delegates everything to == {version}.*.

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.

4 participants