On Mon, Jul 17, 2017 at 8:16 PM, Barry Warsaw <[email protected]> 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)
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com