Skip to content

Preserve dict LIFO order in Box.popitem - #341

Open
machines-6657 wants to merge 1 commit into
cdgriffith:developfrom
machines-6657:codex/box-popitem-lifo
Open

machines-6657 wants to merge 1 commit into
cdgriffith:developfrom
machines-6657:codex/box-popitem-lifo

Conversation

@machines-6657

Copy link
Copy Markdown

Fix Box.popitem() to follow dictionary LIFO ordering

Box is documented as a near drop-in replacement for dict, but Box.popitem() removed the first inserted key while Python's dict.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 through Box.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 check pass locally. The test suite was run with PYTHONUTF8=1 because 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.rst directs code changes to develop, and no AI-contribution prohibition was found in the repository instructions or contribution files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant