This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author fhaxbox66@googlemail.com
Recipients fhaxbox66@googlemail.com
Date 2014-10-06.05:06:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1412572010.78.0.424974650415.issue22562@psf.upfronthosting.co.za>
In-reply-to
Content
Each call of namedtuple will create a new class object even if an equal class, i.e. for the same fields has been created before.
Applying the singleton pattern would be more efficient at least in two respects: 
* it would reduce the number of class objects.
* checking for field names can be done by calling isinstance.

I therefore propose a new boolean keyword argument 'singleton' for the namedtuple function. It should 
default to True. If a pre-existing rather than new class object is returned, the provided class name is 
disregarded. In many cases, the caller will use a local binding anyway.
 
The singleton pattern could be implemented along the following schema:

cache = {}
if not fields in cache:
    cache[fields] = new_namedtuple
return cache[fields]
History
Date User Action Args
2014-10-06 05:06:50fhaxbox66@googlemail.comsetrecipients: + fhaxbox66@googlemail.com
2014-10-06 05:06:50fhaxbox66@googlemail.comsetmessageid: <1412572010.78.0.424974650415.issue22562@psf.upfronthosting.co.za>
2014-10-06 05:06:50fhaxbox66@googlemail.comlinkissue22562 messages
2014-10-06 05:06:50fhaxbox66@googlemail.comcreate