[Python-ideas] namedtuple baseclass

Yury Selivanov yselivanov.ml at gmail.com
Sun Jan 12 17:45:44 CET 2014


Eric,

On Sun, Jan 12, 2014 at 11:33 AM, Eric Snow <ericsnowcurrently at gmail.com> wrote:
>
> On Jan 12, 2014 5:52 AM, "Yury Selivanov" <yselivanov.ml at gmail.com> wrote:
>> BTW, ABC proposal aside: the current namedtuple implementation
>> creates the class from a template with "exec" call. For every namedtuple,
>> it's entire set of methods is created over and over again. Even for the
>> memory efficiency sake, having a base class with *some* of the common
>> methods (which are currently in the template) is better.
>
> It's a trade-off.  We increase the definition-time cost by using exec, but
> minimize the cost of traversing the attribute lookup chain when using
> instances.  The purely ABC approach in the referenced issue preserves this
> instance-favoring-optimization design.
>
> -eric

Correct me if i'm wrong, but what's the point of speeding up (2%?) attribute
lookup on "_make", "__repr__", and other namedtuple methods?  What matters
is the performance of "__getitem__" and field property access, but that would
be the same if a metaclass (or simple "type" call) is used to construct
nametuples.

Anyways, I'm not proposing to touch the main bulk of the current implementation
(and perhaps there are another reasons why it is as it is). The only
thing I think
would be nice to have (for now), is to have a base class for namedtuples other
than tuple.


Thank you,
Yury


More information about the Python-ideas mailing list