Repository navigation
Evaluate untyped_sorted keys once per item - #552
Closed
Gambit-Checkmate wants to merge 1 commit into
Closed
Gambit-Checkmate wants to merge 1 commit into
Gambit-Checkmate wants to merge 1 commit into
Conversation
This was referenced Oct 7, 2026
Saadia751
reviewed
Oct 14, 2026
Saadia751
left a comment
There was a problem hiding this comment.
I checked a key that records its calls while sorting a mixture of numbers and strings. Each original item is evaluated once, the returned values remain the original items, and equal-key order stays stable with reverse either way. A key exception also propagates rather than being swallowed.
Checked 03688670cd45 with standalone Python 3.12.14 checks (9 passing assertions). I haven't run the full upstream suite.
Owner
|
Folded into #609 (see the PR description for credit). Thanks for the report and the repro. |
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.
The change
Evaluate
untyped_sorted's key once per input item, before comparisons, likesorted. Previously comparison-time evaluation repeatedly ran expensive or stateful keys and skipped singleton key errors. Cache the key in the existing wrapper; retain mixed-type fallback ordering and stable equal-key order. Document the behavior and cover generators, ascending/descending mixed keys, singleton errors, and stable ties.Verification on Windows/Python 3.13.13: the new tests fail before the fix (3 failures, 1 pass), then
python -m pytest --doctest-modules boltons tests -qpasses: 682 tests and 12 subtests. No runtime dependencies added.The backstory
This contribution was investigated and prepared by Codex at the account owner's request to contribute tested fixes to established open-source projects. I found the problem while inspecting sorting helpers after checking candidate issues and existing PRs; I do not claim that the human contributor encountered it in a personal application. The architecture guidance's standard-library consistency rule informed the comparison with
sorted.AI assistance
Fixes #551.
GitHub Actions is awaiting maintainer approval for this external contribution (action_required): https://github.com/mahmoud/boltons/actions/runs/37569573870 . Local full validation passed; Read the Docs preview build passed.