Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Code contributions:
- Jesper Schlegel (jesperschlegel)
- J vanBemmel (jbemmel)
- m-janicki
- machines-6657 (machines-6657)


Suggestions and bug reporting:
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

Unreleased
----------

* Fix `Box.popitem()` to remove the most recently inserted item, matching `dict.popitem()`.

Version 7.4.1
-------------

Expand Down
2 changes: 1 addition & 1 deletion box/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def popitem(self):
if self._box_config["frozen_box"]:
raise BoxError("Box is frozen")
try:
key = next(self.__iter__())
key = next(self.__reversed__())
except StopIteration:
raise BoxKeyError("Empty box") from None
return key, self.pop(key)
Expand Down
3 changes: 2 additions & 1 deletion test/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ def test_pop(self):
assert bx.pop("c", True) is not True

def test_pop_items(self):
bx = Box(a=4)
bx = Box(a=4, b=5)
assert bx.popitem() == ("b", 5)
assert bx.popitem() == ("a", 4)
with pytest.raises(BoxKeyError):
assert bx.popitem()
Expand Down