Repository navigation
Conversation
This branch has not been deployed
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
Preserve source iteration order in the set-based branch of
dissoc().The function currently copies and deletes when relatively few keys are supplied, but constructs a set of surviving keys and iterates that set when
len(keys) >= len(d) * .6. As a result, the order of a returned dict or OrderedDict depends on which internal strategy is selected. Duplicate or nonexistent removal keys can trigger the reordering even when few or no entries are actually removed.For example:
The fix retains the existing remaining-key set, but iterates the source mapping and copies surviving entries in source order. Overall linear complexity is unchanged. The docstring states the insertion-order behavior.
Validation
Sixteen regression cases cover dict and OrderedDict inputs and output factories, small/large removal sets, absent keys, repeated keys, result type, and unchanged source items. Before the fix: 12 failures and 4 passing controls. After the fix:
python -m pytest --doctest-modules toolz/ -q --tb=short: 284 passed, 2 skipped on Windows / CPython 3.13.5. The skips are an explicitly skipped doctest and a Python 3.14-only annotationlib test.git diff --checkpassed.Other interpreter/platform combinations were not tested locally. Prepared with OpenAI Codex assistance for investigation, implementation, tests and this description.