util/version: fix SemanticVersion comparison precedence#1797
Merged
Conversation
The old __lt__, __le__, __gt__, __ge__ short-circuited on the first field that differed, returning True as soon as any of major/minor/patch satisfied the relation. That meant 1.0.0 < 0.5.0 returned True (minor 0 < 5) and 2.0.0 > 1.99.99 returned False, breaking the modpack "outdated" check in convert/service/init/changelog.py. Switch to a tuple precedence key and use functools.total_ordering, so the operators agree with each other by construction. Prerelease versions now sort below the same MAJOR.MINOR.PATCH per semver 11.3; full identifier-by-identifier comparison (semver 11.4) is noted as not yet implemented. Build metadata is ignored for precedence, which matches semver 10. Add doctests covering the regressions and register openage.util.version in testing/testlist.py so they actually run.
This was referenced May 28, 2026
This was referenced May 29, 2026
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.
Merge Checklist
make checkmergeand fixed all mentioned problems (no local build setup; relying on CI)Description
SemanticVersion.__lt__/__le__/__gt__/__ge__inopenage/util/version.pyshort-circuit on the first field that differs and returnTrueas soon as any ofmajor/minor/patchsatisfies the relation, instead of comparing fields lexicographically. The bug:The only current caller is
openage/convert/service/init/changelog.py:43, which uses>to decide whether a converted modpack is outdated, so this silently flipped some "up-to-date" vs "outdated" decisions.Fix
Switch the operators to a tuple precedence key and use
functools.total_ordering, so the operators agree with each other by construction. Prerelease versions now sort below the sameMAJOR.MINOR.PATCHper semver 11.3. Build metadata is ignored for precedence, matching semver 10. Full identifier-by-identifier prerelease comparison (semver 11.4, i.e.alpha < beta < rc) is noted as not yet implemented; the current usage inchangelog.pydoes not need it.Tests
Added inline doctests covering the regression cases, and registered
openage.util.versioninopenage/testing/testlist.pydoctest_modules()so they run as part of the doctest suite.