diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index febab521629228..f03397ff407c73 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 last-in, first-out instead of first-in, first-out. + def popitem(self): + return self.data.popitem() + + @classmethod def fromkeys(cls, iterable, value=None): d = cls() 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..208b47fc312a3f --- /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 like ``dict``.