[New-bugs-announce] [issue9507] namedtuple should not hardcode the class name in __repr__

Paul Giannaros report at bugs.python.org
Wed Aug 4 13:48:15 CEST 2010


New submission from Paul Giannaros <paul at giannaros.org>:

collections.namedtuple hardcodes the class name which is reported in the new type's __repr__. This is irritating when subclassing a namedtuple:

A = collections.namedtuple('A', '')
class B(A):
    pass
print B()  # shows 'A()'

It might not be often that they're subclassed, but it can be a useful way to add extra methods, properties, and documentation. Other classes often use the current instance's class name in the repr (e.g. collections.OrderedDict). The attached patch changes namedtuple to do this, includes a testcase, and updates the documentation.

----------
components: Library (Lib)
files: collections-namedtuple-repr.diff
keywords: patch
messages: 112792
nosy: PAG
priority: normal
severity: normal
status: open
title: namedtuple should not hardcode the class name in __repr__
type: behavior
versions: Python 2.6, Python 2.7, Python 3.3
Added file: http://bugs.python.org/file18377/collections-namedtuple-repr.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9507>
_______________________________________


More information about the New-bugs-announce mailing list