From 5681cbce812d3daf19eab3a58631076148aa22c8 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 15 Nov 2007 02:55:42 +0000 Subject: Small improvement to the implementation of __replace__(). --- Doc/library/collections.rst | 2 +- Lib/collections.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 2d7f0a9..1e7b427 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -396,7 +396,7 @@ Example:: return dict(zip(('x', 'y'), self)) def __replace__(self, field, value): 'Return a new Point object replacing specified fields with new values' - return Point(**dict(self.__asdict__().items() + kwds.items())) + return Point(**dict(zip(('x', 'y'), self) + kwds.items())) x = property(itemgetter(0)) y = property(itemgetter(1)) diff --git a/Lib/collections.py b/Lib/collections.py index 6b2e58d..7381a3a 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -64,7 +64,7 @@ def namedtuple(typename, field_names, verbose=False): return dict(zip(%(field_names)r, self)) def __replace__(self, **kwds): 'Return a new %(typename)s object replacing specified fields with new values' - return %(typename)s(**dict(self.__asdict__().items() + kwds.items())) \n''' % locals() + return %(typename)s(**dict(zip(%(field_names)r, self) + kwds.items())) \n''' % locals() for i, name in enumerate(field_names): template += ' %s = property(itemgetter(%d))\n' % (name, i) if verbose: -- cgit v0.12