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

The result of some case of version compare is not expected #405

Closed
linxingyun opened this issue Feb 24, 2021 · 5 comments
Closed

The result of some case of version compare is not expected #405

linxingyun opened this issue Feb 24, 2021 · 5 comments

Comments

@linxingyun
Copy link

Here are some cases of version compare.

Expected result:

version.parse('v6.4.4-build4832') > version.parse('v6.5')
False
version.parse('v6.4.4-build4832') > version.parse('v6.4.4-build')
True

Note expected result:

version.parse('v6.4.4-build4832') > version.parse('v6.4')
False
version.parse('v6.4.4-build4832') > version.parse('v6.4.4-')
False

Note: This may not be expected, since 'v6.4.4' should be greater than 'v6.4'. But it return back 'False' result.
Please help to confirm this issue. Thank you so much.

@brettcannon
Copy link
Member

This is expected as e.g. v6.4.9 is also a version of v6.4. So when you drop an entire portion of the version then it is expected to always be greater since it will always be somehow compatible with any v6.4.* version.

I also couldn't find a section in PEP 440 (which you get redirected to from https://packaging.python.org/specifications/version-specifiers/) which suggests that dropping the last digit means it should be considered smaller than a version with it specified. If you can point that out that would be really helpful.

@uranusjr
Copy link
Member

I believe PEP 440 is irrelevant here since v6.4.4-build4832 is not a valid PEP 440 version in the first place. This is exactly why we should get rid of LegacyVersion.

@pradyunsg
Copy link
Member

See #386 for context on what's happening with LegacyVersion. It's now deprecated per #321 and, we aren't going to be making changes to LegacyVersion anyway.

The suggestion here is to use packaging.versions.Version, and to use PEP 440-based versions.

@MrMino
Copy link
Contributor

MrMino commented Feb 25, 2021

Also, build4832 looks like a build number to me, shouldn't it be added within the build tag of the wheel?

@linxingyun
Copy link
Author

Thank you guys.

The version build format is not controlled by myself. So it seems to be issue of 'build' text in the version text.

version.parse('v6.4.4-4832') > version.parse('v6.4')
True
version.parse('v6.4.4-b4832') > version.parse('v6.4')
True
version.parse('v6.4.4-build4832') > version.parse('v6.4')
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

5 participants