Add error-checking to namedtuple's _replace() method.

This commit is contained in:
Raymond Hettinger 2008-01-05 02:17:24 +00:00
parent 02740f73ff
commit 1b50fd7cb3
3 changed files with 15 additions and 2 deletions

View file

@ -410,7 +410,10 @@ Example::
def _replace(self, **kwds):
'Return a new Point object replacing specified fields with new values'
return self.__class__._make(map(kwds.get, ('x', 'y'), self))
result = self.__class__._make(map(kwds.pop, ('x', 'y'), self))
if kwds:
raise ValueError('Got unexpected field names: %r' % kwds.keys())
return result
x = property(itemgetter(0))
y = property(itemgetter(1))