Fix GentooVersion and AlpineLinuxVersion missing __le__ and __ge__ operators - #187
Open
xovishnukosuri wants to merge 1 commit into
Open
xovishnukosuri wants to merge 1 commit into
xovishnukosuri wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #172
GentooVersionoverrides__eq__,__lt__, and__gt__to usegentoo.vercmpfor correct numeric version ordering, but was missing__le__and__ge__. Theattrs-generated fallback methods compared the raw stringvalueattribute directly, which caused lexicographic ordering instead of numeric ordering for those two operators.Concrete example of the bug:
AlpineLinuxVersioninherits fromGentooVersionso it had the same bug.Changes
__le__and__ge__toGentooVersionusinggentoo.vercmp, consistent with the existing__lt__and__gt__implementations.AlpineLinuxVersioninherits the fix automatically since it subclassesGentooVersion.test_versions.pyfor bothGentooVersionandAlpineLinuxVersioncovering the numeric-vs-lexicographic ordering edge case (1.2.0<1.10.0numerically but>lexicographically).Test plan
pytest tests/test_versions.py::test_gentoo_versionpassespytest tests/test_versions.py::test_alpine_linux_versionpassespytest tests/test_gentoo.pypasses (all 48 tests)pytest tests/test_versions.pypasses (pre-existing unrelated failures in semver tests are unchanged)🤖 Generated with Claude Code