Steven D'Aprano <steve at pearwood.info> writes: > 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 In this case, wouldn't it be nicer to "decorate" those attributes that are meant to be enum values? I think having to use the class keyword to define something that really doesn't behave like an ordinary class is pretty confusing, and the following syntax would be a lot easier to understand at first sight: class Insect(enum.Enum): ant = enum.EnumValue(1) bee = enum.EnumValue(2) @classmethod def spam(cls, args): pass def ham(self, args): pass Obviously, EnumValue() would automatically assign a suitable number. Best, -Nikolaus -- »Time flies like an arrow, fruit flies like a Banana.« PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
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