[Python-Dev] constant/enum type in stdlib
ncoghlan at gmail.com
Tue Nov 30 03:23:04 CET 2010
On Tue, Nov 30, 2010 at 7:36 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> I don't see how the grouping can be completely separated
> from the value-naming. If the named values are to be
> subclassed from the base values, then you want all the
> members of a group to belong to the *same* subclass.
> You can't get that by treating each named value on its
> own and then trying to group them together afterwards.
Note that my sample implementation cached the created types, so that
(for example) there was only ever one "Named<int>" type (my
implementation wasn't quite kosher in that respect, since
functools.lru_cache has a non-optional size limit - setting maxsize to
float('inf') deals with that). A grouping API would use either single
or multiple inheritance to create members that supported both the
naming aspects as well as the grouping aspects.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev