Skip to content

Commit

Permalink
Fix handling of optional default value for .pop() (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecee authored Mar 4, 2024
1 parent dd58934 commit 3dd16c6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions easydict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class EasyDict(dict):
Traceback (most recent call last):
...
AttributeError: 'EasyDict' object has no attribute 'a'
>>> d.pop('a', 8)
8
>>> d.pop('b', 100)
4
>>> d
{'c': 3.0}
"""
def __init__(self, d=None, **kwargs):
if d is None:
Expand Down Expand Up @@ -155,9 +161,10 @@ def update(self, e=None, **f):
for k in d:
setattr(self, k, d[k])

def pop(self, k, d=None):
delattr(self, k)
return super(EasyDict, self).pop(k, d)
def pop(self, k, *args):
if hasattr(self, k):
delattr(self, k)
return super(EasyDict, self).pop(k, *args)


if __name__ == "__main__":
Expand Down

0 comments on commit 3dd16c6

Please sign in to comment.