Skip to content

gh-147957: pop items from UserDict in LIFO order#147958

Open
Andrew5057 wants to merge 6 commits intopython:mainfrom
Andrew5057:lifo-userdict-popitem
Open

gh-147957: pop items from UserDict in LIFO order#147958
Andrew5057 wants to merge 6 commits intopython:mainfrom
Andrew5057:lifo-userdict-popitem

Conversation

@Andrew5057
Copy link
Copy Markdown

@Andrew5057 Andrew5057 commented Apr 1, 2026

UserDict.popitem used to pop last-in, first-out since that's the MutableMapping implementation. This PR makes it pop last-in, first-out since that's the behavior guaranteed for dict starting in Python 3.7. Given that the purpose of UserDict is to make pseudo-subclassing dict easier, this method should align with its behavior in dict to avoid unexpected behavior.

`UserDict.popitem` used to pop first-in, first-out since that's the
`MutableMapping` implementation. It now pops first-in, last-out since
that's the behavior guaranteed for `dict` starting in Python 3.7.
@Andrew5057 Andrew5057 requested a review from rhettinger as a code owner April 1, 2026 07:03
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 1, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Apr 1, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

blurb-it bot and others added 5 commits April 1, 2026 07:10
The last commit used the wrong verbiage in a comment. This fixes it and
clarifies that MutableMapping uses FIFO.
Switch from single to double backticks for inline code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants