Skip to content

Implement __le__ and __ge__ for GentooVersion - #211

Open
ArneshBanerjee wants to merge 1 commit into
aboutcode-org:mainfrom
ArneshBanerjee:fix-gentoo-le-ge
Open

Implement __le__ and __ge__ for GentooVersion#211
ArneshBanerjee wants to merge 1 commit into
aboutcode-org:mainfrom
ArneshBanerjee:fix-gentoo-le-ge

Conversation

@ArneshBanerjee

@ArneshBanerjee ArneshBanerjee commented Aug 31, 2026

Copy link
Copy Markdown

Fixes #172

GentooVersion defines __eq__, __lt__ and __gt__, but not __le__ and __ge__. Those two fall back to the ones generated by @attr.s(order=True) on the Version base class, which compare the raw version strings. That gives the wrong answer when string order and version order do not agree.

>>> from univers.versions import GentooVersion
>>> GentooVersion("1.2.0-r0") <= GentooVersion("1.10.0-r0")
False
>>> GentooVersion("1.10.0-r0") >= GentooVersion("1.2.0-r0")
False

AlpineLinuxVersion extends GentooVersion, so it had the same problem.

This adds __le__ and __ge__ that use gentoo.vercmp, the same way ArchLinuxVersion already does, plus tests for both classes.

GentooVersion only defined __eq__, __lt__ and __gt__, so <= and >= fell back
to the attrs generated ones that compare raw version strings. This was wrong
whenever string order differs from version order, for example
GentooVersion("1.2.0-r0") <= GentooVersion("1.10.0-r0") returned False.
AlpineLinuxVersion inherits from GentooVersion and had the same problem.

fixes: aboutcode-org#172
Signed-off-by: Arnesh <linkrinku13@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gentoo/Alpine version doesn't implement <= or >= correctly

1 participant