From: Raymond Hettinger Date: Mon, 7 Jan 2008 20:56:05 +0000 (+0000) Subject: Use get() instead of pop() for the optimized version of _replace(). X-Git-Tag: v2.6a1~680 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5e8af1bb7e375e86298ae7a4ee5b6c3e8a22db4;p=python Use get() instead of pop() for the optimized version of _replace(). --- diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index e797296418..fb9b958909 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -531,7 +531,7 @@ faster versions that bypass error-checking and localize variable access:: >>> class Point(namedtuple('Point', 'x y')): _make = classmethod(tuple.__new__) def _replace(self, _map=map, **kwds): - return self._make(_map(kwds.pop, ('x', 'y'), self)) + return self._make(_map(kwds.get, ('x', 'y'), self)) Default values can be implemented by using :meth:`_replace` to customize a prototype instance:: diff --git a/Lib/collections.py b/Lib/collections.py index c19821bb39..099cdd62bd 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -130,7 +130,7 @@ if __name__ == '__main__': 'Point class with optimized _make() and _replace() without error-checking' _make = classmethod(tuple.__new__) def _replace(self, _map=map, **kwds): - return self._make(_map(kwds.pop, ('x', 'y'), self)) + return self._make(_map(kwds.get, ('x', 'y'), self)) print Point(11, 22)._replace(x=100)