Consider the following snippet:
from collections import UserDict
class D(dict): ...
d = D(foo="bar", baz=42)
print(d.popitem()) # ('baz', 42)
class UD(UserDict): ...
ud = UD(foo="bar", baz=42)
print(ud.data) # {'foo': 'bar', 'baz': 42}
print(ud.popitem()) # ('foo', 'bar')
The order seems to be preserved in the UserDict implementation as it should since it internally uses a data dict which is ordered since 3.7.
Why is the popped item the first one and not the last one? Am I misunderstanding something? Is this a bug or a feature?
Tested on 3.13.9 and 3.14.0 in fresh environments.
ud.data.popitem()instead ofud.popitem().