Author: Alex Gaynor <[email protected]>
Branch: kill-single-impl-multimethods
Changeset: r46339:c1a1ef97c910
Date: 2011-08-06 15:56 -0700
http://bitbucket.org/pypy/pypy/changeset/c1a1ef97c910/
Log: setdefault's value argument is optional.
diff --git a/pypy/objspace/std/dicttype.py b/pypy/objspace/std/dicttype.py
--- a/pypy/objspace/std/dicttype.py
+++ b/pypy/objspace/std/dicttype.py
@@ -129,7 +129,7 @@
(if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k]
= F[k]"""
init_or_update(space, self, __args__, 'dict.update')
- def descr_setdefault(self, space, w_key, w_value):
+ def descr_setdefault(self, space, w_key, w_value=None):
"""D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D"""
return self.setdefault(w_key, w_value)
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py
b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -269,6 +269,9 @@
d[33] = 99
assert d == dd
assert x == 99
+ x = dd.setdefault(12)
+ assert x is None
+ assert dd[12] is None
def test_setdefault_fast(self):
class Key(object):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit