Skip to content

Commit

Permalink
refactor(stdlib)!: Now dict().pop raises NotImplementedError
Browse files Browse the repository at this point in the history
In older python versions there is no `pop` method
  • Loading branch information
LukeSavefrogs committed Aug 4, 2023
1 parent 491bc16 commit 1199cc1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/polyfills/stdlib/future_types/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ def items(self, *args, **kwargs):
def keys(self, *args, **kwargs):
return self.__dict__.keys(*args, **kwargs)

# TODO: Implement a custom method for dict.pop
def pop(self, *args, **kwargs):
return self.__dict__.pop(*args, **kwargs)
raise NotImplementedError("%s.pop() is not implemented" % self.__class__.__name__)

def popitem(self):
raise NotImplementedError("%s.popitem() is not implemented" % self.__class__.__name__)
Expand Down Expand Up @@ -322,9 +323,7 @@ def test_keys(self):

def test_pop(self):
d = dict(first=1, second=2)
self.assertEqual(d.pop("first"), 1)
self.assertEqual(d, {"second": 2})
self.assertEqual(d.pop("third", None), None)
self.assertRaises(NotImplementedError, lambda: d.pop("first"))

def test_popitem(self):
self.assertRaises(NotImplementedError, lambda: dict().popitem())
Expand Down

0 comments on commit 1199cc1

Please sign in to comment.