[Python-Dev] Impact of Namedtuple on startup time

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Jul 17 21:14:38 EDT 2017


On Mon, Jul 17, 2017 at 8:16 PM, Barry Warsaw <barry at python.org> wrote:

> ..
> >   class Foo(NamedTuple, fields = 'x,y,z'):
> >      ...
> >
> > Then the name is explicit and you get to add methods
> > etc. if you want.
>
> Yes, I like how that reads.
>
>
I would prefer

 class Foo(metaclass=namedtuple, fields = 'x,y,z'):
   ...

which while slightly more verbose, does not lie about what namedtuple is -
a factory of classes.  This, however is completely orthogonal to the issue
of performance.  As I mentioned in my previous post, namedtuple metaclass
above can be a simple function:

def namedtuple(name, bases, attrs, fields=()):
        # Override __init_subclass__ for Python 3.6
        return collections.namedtuple(name, fields)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170717/6e5ee91f/attachment-0001.html>


More information about the Python-Dev mailing list