Message228640
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] |
|
Date |
User |
Action |
Args |
2014-10-06 05:06:50 | fhaxbox66@googlemail.com | set | recipients:
+ fhaxbox66@googlemail.com |
2014-10-06 05:06:50 | fhaxbox66@googlemail.com | set | messageid: <1412572010.78.0.424974650415.issue22562@psf.upfronthosting.co.za> |
2014-10-06 05:06:50 | fhaxbox66@googlemail.com | link | issue22562 messages |
2014-10-06 05:06:50 | fhaxbox66@googlemail.com | create | |
|