diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-05 02:17:24 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-05 02:17:24 (GMT) |
commit | 1b50fd7cb3e9a4483f6da49c027ebde4501d1c17 (patch) | |
tree | 5fbe7ba58aafb667a6c6e14920e17a7f19f9456c /Lib/collections.py | |
parent | 02740f73ff0f12d276ef16b73208d4f9f8d62baa (diff) | |
download | cpython-1b50fd7cb3e9a4483f6da49c027ebde4501d1c17.zip cpython-1b50fd7cb3e9a4483f6da49c027ebde4501d1c17.tar.gz cpython-1b50fd7cb3e9a4483f6da49c027ebde4501d1c17.tar.bz2 |
Add error-checking to namedtuple's _replace() method.
Diffstat (limited to 'Lib/collections.py')
-rw-r--r-- | Lib/collections.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/collections.py b/Lib/collections.py index 2a58b86..9985f93 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -78,7 +78,10 @@ def namedtuple(typename, field_names, verbose=False): return {%(dicttxt)s} \n def _replace(self, **kwds): 'Return a new %(typename)s object replacing specified fields with new values' - return self.__class__._make(map(kwds.get, %(field_names)r, self)) \n\n''' % locals() + result = self.__class__._make(map(kwds.pop, %(field_names)r, self)) + if kwds: + raise ValueError('Got unexpected field names: %%r' %% kwds.keys()) + return result \n\n''' % locals() for i, name in enumerate(field_names): template += ' %s = property(itemgetter(%d))\n' % (name, i) if verbose: |