diff -r a2e71ebc9df0 Lib/collections.py --- a/Lib/collections.py Wed Aug 04 12:27:51 2010 +0200 +++ b/Lib/collections.py Wed Aug 04 12:13:13 2010 +0100 @@ -243,7 +243,7 @@ return result \n def __repr__(self): 'Return a nicely formatted representation string' - return '%(typename)s(%(reprtxt)s)' %% self \n + return self.__class__.__name__ + '(%(reprtxt)s)' %% self \n def _asdict(self): 'Return a new OrderedDict which maps field names to their values' return OrderedDict(zip(self._fields, self)) \n diff -r a2e71ebc9df0 Lib/test/test_collections.py --- a/Lib/test/test_collections.py Wed Aug 04 12:27:51 2010 +0200 +++ b/Lib/test/test_collections.py Wed Aug 04 12:26:19 2010 +0100 @@ -215,6 +215,16 @@ # test __getnewargs__ self.assertEqual(t.__getnewargs__(), values) + def test_repr(self): + with test_support.captured_stdout() as template: + A = namedtuple('A', 'x', verbose=True) + self.assertEqual(repr(A(1)), 'A(x=1)') + # repr should show the name of the subclass + class B(A): + pass + self.assertEqual(repr(B(1)), 'B(x=1)') + + class ABCTestCase(unittest.TestCase): def validate_abstract_methods(self, abc, *names): diff -r a2e71ebc9df0 Doc/library/collections.rst --- a/Doc/library/collections.rst Wed Aug 04 12:27:51 2010 +0200 +++ b/Doc/library/collections.rst Wed Aug 04 12:43:39 2010 +0100 @@ -736,7 +736,7 @@ def __repr__(self): 'Return a nicely formatted representation string' - return 'Point(x=%r, y=%r)' % self + return self.__class__.__name__ + '(x=%r, y=%r)' % self def _asdict(self): 'Return a new OrderedDict which maps field names to their values'