[Python-ideas] namedtuple() subclasses again

Raymond Hettinger raymond.hettinger at gmail.com
Sun Mar 27 23:40:55 CEST 2011

On Mar 27, 2011, at 1:53 PM, Jan Kaliszewski wrote:
> Another approach could be a decorator transforming a given class into
> namedtuple with methods defined in that class:
>    @namedtuple.from_class
>    class MyRecord:  # or e.g. class MyRecord(MyMixinWithSomeMethods):
>        fields = 'username password'
>        def __str__(self):
>            return '{0.__class__}({0.username}, ...)'.format(self)

For the record (pun intended), I'm opposed to changing the API for namedtuples.

It is a mature, successful API that stands to benefit very little from from making a second way to do it.

Experimentation is great and it would be nice to have alternative recipes posted in the ASPN Cookbook or some other place, but I believe the standard library is the wrong place to fiat in a second way to create them.  If a new recipe gains traction, we can link to it from the docs.

Python development is currently suffering from excess enthusiasm with advanced code manipulations occurring upon instantiation -- metaclasses, decorators, and context managers are fun to play with, but no fun to debug or trace through when something goes wrong.


More information about the Python-ideas mailing list