{{ message }}
Fix sorted() to use __lt__ instead of __gt__ - #6887
Merged
Merged
Conversation
Contributor
Contributor
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] test: cpython/Lib/test/test_peepholer.py (TODO: 32) dependencies: dependent tests: (no tests depend on peepholer) Legend:
|
youknowone
marked this pull request as ready for review
January 28, 2026 01:24
Contributor
CPython's sort uses __lt__ for comparisons, but RustPython was using __gt__. This caused issues when only __lt__ was overridden on a subclass (e.g., NamedTuple with custom __lt__), as it would fall back to the parent class's comparison instead of using the overridden method.
youknowone
enabled auto-merge (squash)
January 28, 2026 07:55
youknowone
disabled auto-merge
January 28, 2026 07:55
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.

CPython's sort uses lt for comparisons, but RustPython was using gt. This caused issues when only lt was overridden on a subclass (e.g., NamedTuple with custom lt), as it would fall back to the parent class's comparison instead of using the overridden method.
Summary by CodeRabbit
__lt__comparison method, aligning with CPython semantics for more predictable results when sorting custom objects.✏️ Tip: You can customize this high-level summary in your review settings.