From d6fed84d3e985b8e199120d8ada8542665a146f2 Mon Sep 17 00:00:00 2001 From: Anerdw Date: Wed, 1 Apr 2026 01:45:05 -0500 Subject: [PATCH 1/5] gh-147957: pop items from UserDict in LIFO order `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. --- Lib/collections/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index febab521629228..d07a9481d1dc22 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -1253,6 +1253,13 @@ def copy(self): c.update(self) return c + + # This method has a default implementation in MutableMapping, but dict's + # equivalent is first-in, first-out. + def popitem(self): + return self.data.popitem() + + @classmethod def fromkeys(cls, iterable, value=None): d = cls() From 791cf0411638037db6911629143fb5bcf6876a6c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:10:50 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst diff --git a/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst b/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst new file mode 100644 index 00000000000000..a40162374cae58 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst @@ -0,0 +1 @@ +Causes the `popitem` method for `collections.UserDict` to pop in last-in, first-out order rather than first-in, first-out. The former has been the default for `dict` instances since Python 3.7, so this change will make subclasses of `UserDict` behave more similarly to `dict`. From cc9bfc9aa368a34011d817ea4c3be16e8ced6d58 Mon Sep 17 00:00:00 2001 From: Anerdw Date: Wed, 1 Apr 2026 02:14:06 -0500 Subject: [PATCH 3/5] Clarify LIFO vs FIFO The last commit used the wrong verbiage in a comment. This fixes it and clarifies that MutableMapping uses FIFO. --- Lib/collections/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index d07a9481d1dc22..f03397ff407c73 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -1255,7 +1255,7 @@ def copy(self): # This method has a default implementation in MutableMapping, but dict's - # equivalent is first-in, first-out. + # equivalent is last-in, first-out instead of first-in, first-out. def popitem(self): return self.data.popitem() From fec74e8b34754df6021cf199685aa74324088fc9 Mon Sep 17 00:00:00 2001 From: Anerdw <84680088+Andrew5057@users.noreply.github.com> Date: Wed, 1 Apr 2026 02:21:32 -0500 Subject: [PATCH 4/5] Fix inline code in NEWS entry Switch from single to double backticks for inline code. --- .../next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst b/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst index a40162374cae58..532887a0d049a1 100644 --- a/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst +++ b/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst @@ -1 +1 @@ -Causes the `popitem` method for `collections.UserDict` to pop in last-in, first-out order rather than first-in, first-out. The former has been the default for `dict` instances since Python 3.7, so this change will make subclasses of `UserDict` behave more similarly to `dict`. +Causes the ``popitem`` method for ``collections.UserDict`` to pop in last-in, first-out order rather than first-in, first-out. The former has been the default for ``dict`` instances since Python 3.7, so this change will make subclasses of `UserDict` behave more like ``dict``. From 6b558a447a363eec814da3d377c424351ff22390 Mon Sep 17 00:00:00 2001 From: Anerdw Date: Wed, 1 Apr 2026 02:25:11 -0500 Subject: [PATCH 5/5] Fix one last single backtick --- .../next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst b/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst index 532887a0d049a1..208b47fc312a3f 100644 --- a/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst +++ b/Misc/NEWS.d/next/Library/2026-04-01-07-10-49.gh-issue-147957.QXf5Xx.rst @@ -1 +1 @@ -Causes the ``popitem`` method for ``collections.UserDict`` to pop in last-in, first-out order rather than first-in, first-out. The former has been the default for ``dict`` instances since Python 3.7, so this change will make subclasses of `UserDict` behave more like ``dict``. +Causes the ``popitem`` method for ``collections.UserDict`` to pop in last-in, first-out order rather than first-in, first-out. The former has been the default for ``dict`` instances since Python 3.7, so this change will make subclasses of ``UserDict`` behave more like ``dict``.