Repository navigation
Preserve dict LIFO order in Box.popitem - #341
Open
machines-6657 wants to merge 1 commit into
Open
machines-6657 wants to merge 1 commit into
machines-6657 wants to merge 1 commit into
Conversation
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.
Fix Box.popitem() to follow dictionary LIFO ordering
Boxis documented as a near drop-in replacement fordict, butBox.popitem()removed the first inserted key while Python'sdict.popitem()removes the most recently inserted key (LIFO, guaranteed since Python 3.7). The existing test used a one-item Box and could not detect the ordering mismatch.This patch changes
Box.popitem()to select the last key through Box's reverse iterator and then removes it throughBox.pop()so the existing key bookkeeping remains in effect. The regression test checks two ordered removals and preserves the empty-Box exception assertion.Validation: the new regression assertion failed before the implementation change and passes after it. The full test suite, repository pre-commit hooks, mypy, Windows Cythonized test hook, wheel build, and
twine checkpass locally. The test suite was run withPYTHONUTF8=1because this Windows host otherwise defaults to GBK and cannot decode an existing TOML fixture.No matching open issue or PR was found during the read-only issue/PR search. The repository's
CONTRIBUTING.rstdirects code changes todevelop, and no AI-contribution prohibition was found in the repository instructions or contribution files.