[Python-ideas] constant/enum type in stdlib

João Bernardo jbvsmo at gmail.com
Mon Feb 4 01:25:55 CET 2013


2013/2/3 Tim Delaney <timothy.c.delaney at gmail.com>

> On 4 February 2013 10:53, João Bernardo <jbvsmo at gmail.com> wrote:
>
>> Hi, about this enum/const thing, The use case I like more is a class
>> where you know all the
>> instances and not just a sequence of names.
>> Particularly It would be nice to have custom attributes and methods
>> besides the value and the name.
>>
>> I have my own implementation with a basic api somewhat borrowed from
>> flufl.enum (plus a lot of other stuff),
>> but with this kind of support: https://github.com/jbvsmo/makeobj
>>
>
> I considered it, and in fact you could almost do it with my implementation
> by using a custom subclass of EnumValue (except trying it has just exposed
> a design flaw with the whole _EnumProxy bit). Works if you create the enum
> in the same module as EnumValues, fails otherwise. Going to have to have a
> rethink.
>
>
For attributes, it would probably be easy to do, but for methods you will
probably need a new _EnumProxy subclass for each class.
I did this with a metaclass factory.


João Bernardo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130203/6c758bcb/attachment.html>


More information about the Python-ideas mailing list