mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Use get() instead of pop() for the optimized version of _replace().
This commit is contained in:
parent
fb3ced663d
commit
f5e8af1bb7
2 changed files with 2 additions and 2 deletions
|
|
@ -531,7 +531,7 @@ faster versions that bypass error-checking and localize variable access::
|
||||||
>>> class Point(namedtuple('Point', 'x y')):
|
>>> class Point(namedtuple('Point', 'x y')):
|
||||||
_make = classmethod(tuple.__new__)
|
_make = classmethod(tuple.__new__)
|
||||||
def _replace(self, _map=map, **kwds):
|
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
|
Default values can be implemented by using :meth:`_replace` to
|
||||||
customize a prototype instance::
|
customize a prototype instance::
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ if __name__ == '__main__':
|
||||||
'Point class with optimized _make() and _replace() without error-checking'
|
'Point class with optimized _make() and _replace() without error-checking'
|
||||||
_make = classmethod(tuple.__new__)
|
_make = classmethod(tuple.__new__)
|
||||||
def _replace(self, _map=map, **kwds):
|
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)
|
print Point(11, 22)._replace(x=100)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue