[Python-checkins] r58976 - in python/trunk: Doc/library/collections.rst Lib/collections.py
raymond.hettinger
python-checkins at python.org
Thu Nov 15 03:55:43 CET 2007
Author: raymond.hettinger
Date: Thu Nov 15 03:55:42 2007
New Revision: 58976
Modified:
python/trunk/Doc/library/collections.rst
python/trunk/Lib/collections.py
Log:
Small improvement to the implementation of __replace__().
Modified: python/trunk/Doc/library/collections.rst
==============================================================================
--- python/trunk/Doc/library/collections.rst (original)
+++ python/trunk/Doc/library/collections.rst Thu Nov 15 03:55:42 2007
@@ -396,7 +396,7 @@
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))
Modified: python/trunk/Lib/collections.py
==============================================================================
--- python/trunk/Lib/collections.py (original)
+++ python/trunk/Lib/collections.py Thu Nov 15 03:55:42 2007
@@ -64,7 +64,7 @@
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:
More information about the Python-checkins
mailing list