[Python-ideas] A subclassing API for named tuples?

Eric Snow ericsnowcurrently at gmail.com
Thu Feb 14 16:32:49 CET 2013


On Feb 14, 2013 6:20 AM, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
> A recurring suggestion for collections.namedtuple is that it would be
> nice to be able to define them like this (as it not only avoids having
> to repeat the class name, but also allows them to play nicely with
> pickle and other name-based reference mechanisms):
>
>     class MyTuple(collections.NamedTuple):
>         __fields__ = "a b c d e".split()

Something similar that I've been using:

@as_namedtuple("a b c d e")
class MyTuple:
    """My namedtuple with extra stuff."""
    @property
    def something_special(self):
        """..."""
        return ...

Support for default values is also something I've added, but that's
relatively orthogonal to this discussion.

-eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130214/a29fb103/attachment.html>


More information about the Python-ideas mailing list