<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 1, 2013 at 1:45 PM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, 1 May 2013 13:43:22 -0700<br>
<div><div class="h5">Eli Bendersky <<a href="mailto:eliben@gmail.com">eliben@gmail.com</a>> wrote:<br>
<br>
> On Wed, May 1, 2013 at 1:33 PM, Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>> wrote:<br>
><br>
> > On Wed, 1 May 2013 13:05:53 -0700<br>
> > Eli Bendersky <<a href="mailto:eliben@gmail.com">eliben@gmail.com</a>> wrote:<br>
> > > On Wed, May 1, 2013 at 11:59 AM, Georg Brandl <<a href="mailto:g.brandl@gmx.net">g.brandl@gmx.net</a>> wrote:<br>
> > ><br>
> > > > Am 01.05.2013 20:44, schrieb Antoine Pitrou:<br>
> > > > > On Wed, 01 May 2013 10:21:30 -0700<br>
> > > > > Ethan Furman <<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>> wrote:<br>
> > > > >> We may not want to /completely/ disallow subclassing.  Consider:<br>
> > > > >><br>
> > > > >> --> class StrEnum(str, Enum):<br>
> > > > >> ...    '''string enums for Business Basic variable names'''<br>
> > > > >> ...<br>
> > > > >> --> class Vendors(StrEnum):<br>
> > > > >> EnumError: subclassing not allowed<br>
> > > > ><br>
> > > > > I don't see the point of disallowing subclassing. It sounds like<br>
> > > > > a pointless restriction.<br>
> > > > ><br>
> > > > > However, perhaps the constructor should forbid the returning of a<br>
> > base<br>
> > > > > type, e.g.:<br>
> > > > ><br>
> > > > > class Season(Enum):<br>
> > > > >     spring = 1<br>
> > > > ><br>
> > > > > class MySeason(Season):<br>
> > > > >     """I look nicer than Season"""<br>
> > > > ><br>
> > > > > MySeason('spring')<br>
> > > > > ...<br>
> > > > > ValueError: Season.spring is not a MySeason instance<br>
> > > > ><br>
> > > > > (what this means is perhaps the subclassing of non-empty enum classes<br>
> > > > > should be forbidden)<br>
> > > ><br>
> > > > That's exactly what's implemented in the ref435 code at the moment.<br>
> > > ><br>
> > > ><br>
> > > It can't be because __call__ is by-value lookup, not by-name lookup.<br>
> ><br>
> > Ok, I've mixed up the example. But, still, since Season(1) should<br>
> > return the Season.spring singleton, I don't see any reasonable thing<br>
> > for MySeason(1) to return. Hence the request to raise an exception.<br>
> ><br>
><br>
> What do you need MySeason for, though? IIUC, you don't ask to allow adding<br>
> enum values in it, so it only leaves adding extra functionality (methods)?<br>
> What are the use cases?<br>
<br>
</div></div>I was talking in the context where subclassing is allowed. I don't<br>
think there's a use-case for subclassing of non-empty enums. On the<br>
other hand, empty enums should probably allow subclassing (they are<br>
"abstract base enums", in a way).<br></blockquote></div><br></div><div class="gmail_extra">I still don't understand what you mean, sorry. Like, this:<br><br>class MyEmptyEnum(Enum):<br></div><div class="gmail_extra">

  pass<br><br></div><div class="gmail_extra">Why would you want to subclass MyEmptyEnum ?<br><br>Or do you mean this:<br><br></div><div class="gmail_extra">class IntEnum(int, Enum):<br></div><div class="gmail_extra">  pass<br>

<br></div><div class="gmail_extra">Now I can have:<br><br></div><div class="gmail_extra">class SocketFamily(IntEnum):<br>  ??<br><br></div><div class="gmail_extra">If it's the latter, then why allow subclassing explicitly just for this reason? I think the explicit approach of:<br>

<br></div><div class="gmail_extra">class SocketFamily(int, Enum):<br><br>Is cleaner anyway, and absolves us of providing yet another enum class to export from the stdlib.<br><br>Eli<br></div></div>