Skip to content

Commit 3dd16c6

Browse files
authored
Fix handling of optional default value for .pop() (#47)
1 parent dd58934 commit 3dd16c6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

easydict/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ class EasyDict(dict):
123123
Traceback (most recent call last):
124124
...
125125
AttributeError: 'EasyDict' object has no attribute 'a'
126+
>>> d.pop('a', 8)
127+
8
128+
>>> d.pop('b', 100)
129+
4
130+
>>> d
131+
{'c': 3.0}
126132
"""
127133
def __init__(self, d=None, **kwargs):
128134
if d is None:
@@ -155,9 +161,10 @@ def update(self, e=None, **f):
155161
for k in d:
156162
setattr(self, k, d[k])
157163

158-
def pop(self, k, d=None):
159-
delattr(self, k)
160-
return super(EasyDict, self).pop(k, d)
164+
def pop(self, k, *args):
165+
if hasattr(self, k):
166+
delattr(self, k)
167+
return super(EasyDict, self).pop(k, *args)
161168

162169

163170
if __name__ == "__main__":

0 commit comments

Comments
 (0)