<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 1, 2013 at 2:07 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">On Wed, May 1, 2013 at 2:04 PM, Eli Bendersky <<a href="mailto:eliben@gmail.com">eliben@gmail.com</a>> wrote:<br>


><br>
><br>
><br>
> On Wed, May 1, 2013 at 2:00 PM, Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>> wrote:<br>
>><br>
>> On Wed, 1 May 2013 13:57:11 -0700<br>
>> Eli Bendersky <<a href="mailto:eliben@gmail.com">eliben@gmail.com</a>> wrote:<br>
>> ><br>
>> > I still don't understand what you mean, sorry. Like, this:<br>
>> ><br>
>> > class MyEmptyEnum(Enum):<br>
>> >   pass<br>
>> ><br>
>> > Why would you want to subclass MyEmptyEnum ?<br>
>> ><br>
>> > Or do you mean this:<br>
>> ><br>
>> > class IntEnum(int, Enum):<br>
>> >   pass<br>
>> ><br>
>> > Now I can have:<br>
>> ><br>
>> > class SocketFamily(IntEnum):<br>
>> >   ??<br>
>> ><br>
>> > If it's the latter, then why allow subclassing explicitly just for this<br>
>> > reason?<br>
>><br>
>> Because I may want to share methods accross all concrete subclasses of<br>
>> IntEnum (or WhateverEnum).<br>
><br>
><br>
> You mean this?<br>
><br>
> class BehaviorMixin:<br>
>   # bla bla<br>
><br>
> class MyBehavingIntEnum(int, BehaviorMixin, Enum):<br>
>   foo = 1<br>
>   bar = 2<br>
<br>
</div></div>It's a common pattern to do this with a base class rather than a<br>
mixin, though, and I think the rule "only allow subclassing empty<br>
enums" makes a lot of sense.<br></blockquote></div><br></div><div class="gmail_extra">I see your point (and Antoine's example in the next email is good), but my concern is that this is a TIMTOWTDI thing, since the same can be achieved with mixins. Specifically, Antoine's example<br>

</div><div class="gmail_extra"> becomes:<br><br>class IETFStatusCode:<br>
    @classmethod<br>
    def from_statusline(cls, line):<br>
        return cls(int(line.split()[0]))<br>
<br>
class HTTPStatusCode(int, IETFStatusCode, Enum):<br>    NOT_FOUND = 404<br><div id=":15q"><br>
class SIPStatusCode(int, IETFStatusCode, Enum):<br>
    RINGING = 180</div><br></div><div class="gmail_extra">Same thing, while keeping the stdlib API cleaner and more minimal. Cleaner because "no subclassing" is a simpler, more explicit, and easier to understand rule than "no subclassing unless base class is devoid of enumeration values". And because we can no longer say "Enum classes are final", which is a relatively familiar and understood semantic.<br>

<br>That said, I don't feel strongly about this so if the above does not convert you, I'm fine with allowing subclassing enum classes that don't define any enums =)<br><br></div><div class="gmail_extra">Eli<br>

<br></div></div>