[pypy-commit] pypy default: Simplify the signature of pop(). Needed anyway because CPython 3.5.3
arigo
pypy.commits at gmail.com
Mon Feb 6 13:56:45 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r89984:3dce7b717294
Date: 2017-02-06 19:56 +0100
http://bitbucket.org/pypy/pypy/changeset/3dce7b717294/
Log: Simplify the signature of pop(). Needed anyway because CPython 3.5.3
adds a test that OrderedDict.pop() can be called with keyword
argument 'default'.
diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -348,21 +348,15 @@
w_value = self.getitem(w_key)
return w_value if w_value is not None else w_default
- @unwrap_spec(defaults_w='args_w')
- def descr_pop(self, space, w_key, defaults_w):
+ def descr_pop(self, space, w_key, w_default=None):
"""D.pop(k[,d]) -> v, remove specified key and return the
corresponding value\nIf key is not found, d is returned if given,
otherwise KeyError is raised
"""
- len_defaults = len(defaults_w)
- if len_defaults > 1:
- raise oefmt(space.w_TypeError,
- "pop expected at most 2 arguments, got %d",
- 1 + len_defaults)
w_item = self.getitem(w_key)
if w_item is None:
- if len_defaults > 0:
- return defaults_w[0]
+ if w_default is not None:
+ return w_default
else:
space.raise_key_error(w_key)
else:
More information about the pypy-commit
mailing list