]> granicus.if.org Git - python/commitdiff
Use get() instead of pop() for the optimized version of _replace().
authorRaymond Hettinger <python@rcn.com>
Mon, 7 Jan 2008 20:56:05 +0000 (20:56 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 7 Jan 2008 20:56:05 +0000 (20:56 +0000)
Doc/library/collections.rst
Lib/collections.py

index e797296418aecce343fe52fe4d45c6318cc63cd7..fb9b9589090ffab9eb6919a5fee02166c63fb9d4 100644 (file)
@@ -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::
index c19821bb396dc7a45d810744ac92361856d6c1b5..099cdd62bdf6f5c4d1d96fba82f9db18b5dd98ad 100644 (file)
@@ -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)