<p>Why not defining new methods/changing the behaviour using a different metaclass?</p>
<p>Victor</p>
<div class="gmail_quote">Le 27 avr. 2013 05:12, "Nikolaus Rath" <<a href="mailto:Nikolaus@rath.org">Nikolaus@rath.org</a>> a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> writes:<br>
> On 26/04/13 13:22, Greg wrote:<br>
>> On 26/04/2013 3:12 p.m., Glenn Linderman wrote:<br>
>>> On 4/25/2013 7:49 PM, Nick Coghlan wrote:<br>
>><br>
>>>> You couldn't create an enum of callables, but that would be a<br>
>>>> seriously weird thing to do anyway....<br>
>>><br>
>>> But aren't all classes callable?<br>
>><br>
>> An enum of classes would be seriously weird as well, I think.<br>
><br>
><br>
> I don't think iscallable will work, since that descriptors like<br>
> staticmethod and classmethod aren't callable. Nor are properties.<br>
><br>
><br>
> I think a solution may be an explicit decorator that tells the<br>
> metaclass not to skip the object into an enum value:<br>
><br>
><br>
> class Insect(enum.Enum):<br>
>     ant = 1<br>
>     bee = 2<br>
><br>
>     @enum.skip<br>
>     @classmethod<br>
>     def spam(cls, args):<br>
>         pass<br>
<br>
<br>
In this case, wouldn't it be nicer to "decorate" those attributes that<br>
are meant to be enum values? I think having to use the class keyword to<br>
define something that really doesn't behave like an ordinary class is<br>
pretty confusing, and the following syntax would be a lot easier to<br>
understand at first sight:<br>
<br>
class Insect(enum.Enum):<br>
    ant = enum.EnumValue(1)<br>
    bee = enum.EnumValue(2)<br>
<br>
    @classmethod<br>
    def spam(cls, args):<br>
         pass<br>
<br>
    def ham(self, args):<br>
         pass<br>
<br>
<br>
Obviously, EnumValue() would automatically assign a suitable number.<br>
<br>
<br>
Best,<br>
<br>
   -Nikolaus<br>
<br>
--<br>
 »Time flies like an arrow, fruit flies like a Banana.«<br>
<br>
  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C<br>
<br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com" target="_blank">http://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com</a><br>
</blockquote></div>