name in a tuple subclass.
<BLANKLINE>
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
<BLANKLINE>
def _asdict(self):
'Return a new OrderedDict which maps field names to their values'
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
# test __getnewargs__
self.assertEqual(t.__getnewargs__(), values)
+ def test_repr(self):
+ with 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):
Extensions
----------
+- Issue #9507: Named tuple repr will now automatically display the right
+ name in a tuple subclass.
+
- Issue #9324: Add parameter validation to signal.signal on Windows in order
to prevent crashes.