summaryrefslogtreecommitdiffstats
path: root/Lib/UserDict.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-03-06 23:54:28 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-03-06 23:54:28 (GMT)
commita3e1e4cd79abe7069c8bc20db65161dd8c68b305 (patch)
tree18ff4fb0f06cc1a684da8ad62ce21a5b14c1a33c /Lib/UserDict.py
parent2b4821347f00b01746562d58390a213924f2b102 (diff)
downloadcpython-a3e1e4cd79abe7069c8bc20db65161dd8c68b305.zip
cpython-a3e1e4cd79abe7069c8bc20db65161dd8c68b305.tar.gz
cpython-a3e1e4cd79abe7069c8bc20db65161dd8c68b305.tar.bz2
SF patch #693753: fix for bug 639806: default for dict.pop
(contributed by Michael Stone.)
Diffstat (limited to 'Lib/UserDict.py')
-rw-r--r--Lib/UserDict.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/UserDict.py b/Lib/UserDict.py
index fb9cdd5..6b5c9da 100644
--- a/Lib/UserDict.py
+++ b/Lib/UserDict.py
@@ -55,8 +55,8 @@ class UserDict:
if not self.has_key(key):
self[key] = failobj
return self[key]
- def pop(self, key):
- return self.data.pop(key)
+ def pop(self, key, *args):
+ return self.data.pop(key, *args)
def popitem(self):
return self.data.popitem()
def __contains__(self, key):
@@ -117,8 +117,16 @@ class DictMixin:
except KeyError:
self[key] = default
return default
- def pop(self, key):
- value = self[key]
+ def pop(self, key, *args):
+ if len(args) > 1:
+ raise TypeError, "pop expected at most 2 arguments, got "\
+ + repr(1 + len(args))
+ try:
+ value = self[key]
+ except KeyError:
+ if args:
+ return args[0]
+ raise
del self[key]
return value
def popitem(self):