Skip to content

Fix GentooVersion and AlpineLinuxVersion missing __le__ and __ge__ operators - #187

Open
xovishnukosuri wants to merge 1 commit into
aboutcode-org:mainfrom
xovishnukosuri:fix/gentoo-alpine-le-ge-comparisons
Open

xovishnukosuri wants to merge 1 commit into
aboutcode-org:mainfrom
xovishnukosuri:fix/gentoo-alpine-le-ge-comparisons

Conversation

@xovishnukosuri

Copy link
Copy Markdown

Summary

Fixes #172

GentooVersion overrides __eq__, __lt__, and __gt__ to use gentoo.vercmp for correct numeric version ordering, but was missing __le__ and __ge__. The attrs-generated fallback methods compared the raw string value attribute directly, which caused lexicographic ordering instead of numeric ordering for those two operators.

Concrete example of the bug:

>>> from univers.versions import GentooVersion
>>> v1 = GentooVersion('1.2.0-r0')
>>> v2 = GentooVersion('1.10.0-r0')
>>> v1 < v2
True   # correct: gentoo.vercmp gives numeric order
>>> v1 <= v2
False  # wrong: falls back to string "1.2.0-r0" <= "1.10.0-r0" which is False lexicographically
>>> v1 >= v2
True   # wrong: same fallback issue

AlpineLinuxVersion inherits from GentooVersion so it had the same bug.

Changes

  • Added __le__ and __ge__ to GentooVersion using gentoo.vercmp, consistent with the existing __lt__ and __gt__ implementations.
  • AlpineLinuxVersion inherits the fix automatically since it subclasses GentooVersion.
  • Added regression tests to test_versions.py for both GentooVersion and AlpineLinuxVersion covering the numeric-vs-lexicographic ordering edge case (1.2.0 < 1.10.0 numerically but > lexicographically).

Test plan

  • pytest tests/test_versions.py::test_gentoo_version passes
  • pytest tests/test_versions.py::test_alpine_linux_version passes
  • pytest tests/test_gentoo.py passes (all 48 tests)
  • Full pytest tests/test_versions.py passes (pre-existing unrelated failures in semver tests are unchanged)

🤖 Generated with Claude Code

…erators

GentooVersion overrides __eq__, __lt__, and __gt__ to use gentoo.vercmp
for correct numeric version ordering, but was missing __le__ and __ge__.
The attrs-generated fallbacks compared the raw string value, causing
lexicographic instead of numeric ordering for those two operators.

For example, GentooVersion("1.2.0-r0") <= GentooVersion("1.10.0-r0")
returned False because "1.2.0-r0" > "1.10.0-r0" lexicographically.

Add __le__ and __ge__ to GentooVersion using gentoo.vercmp, which
AlpineLinuxVersion inherits automatically. Add regression tests for both
classes covering the numeric vs lexicographic ordering edge case.

Fixes aboutcode-org#172

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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