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

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Feb 14 23:31:47 CET 2013


Nick Coghlan wrote:
 >
>     class MyTuple(collections.NamedTuple):
>         __fields__ = "a b c d e".split()
> 
> However, one of Raymond's long standing objections to such a design
> for namedtuple is the ugliness of people having to remember to include
> the right __slots__ definition to ensure it doesn't add any storage
> overhead above and beyond that for the underlying tuple.

So why not kill two definitions with one stone and spell
it like this:

      class MyTuple(collections.NamedTuple):
          __slots__ = "a b c d e".split()

-- 
Greg





More information about the Python-ideas mailing list