A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-April/125591.html below:

[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard librarySteven D'Aprano steve at pearwood.info
Fri Apr 26 07:01:06 CEST 2013
On 26/04/13 13:22, Greg wrote:
> On 26/04/2013 3:12 p.m., Glenn Linderman wrote:
>> On 4/25/2013 7:49 PM, Nick Coghlan wrote:
>
>>> You couldn't create an enum of callables, but that would be a
>>> seriously weird thing to do anyway....
>>
>> But aren't all classes callable?
>
> An enum of classes would be seriously weird as well, I think.


I don't think iscallable will work, since that descriptors like
staticmethod and classmethod aren't callable. Nor are properties.


I think a solution may be an explicit decorator that tells the
metaclass not to skip the object into an enum value:


class Insect(enum.Enum):
     ant = 1
     bee = 2

     @enum.skip
     @classmethod
     def spam(cls, args):
         pass


assert isinstance(Insect.spam, classmethod)



One side effect of this is that now you can (ab)use the decorator
to have regular data attributes. Whether that counts as a good
thing or a bad thing, I leave up to others to decide...




-- 
Steven
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4