<div dir="ltr">On 12 February 2013 00:28, Eli Bendersky <span dir="ltr"><<a href="mailto:eliben@gmail.com" target="_blank">eliben@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><span style="color:rgb(80,0,80)">On Sun, Feb 10, 2013 at 2:43 PM, Tim Delaney </span><span dir="ltr" style="color:rgb(80,0,80)"><<a href="mailto:timothy.c.delaney@gmail.com" target="_blank">timothy.c.delaney@gmail.com</a>></span><span style="color:rgb(80,0,80)"> wrote:</span><br>
<div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div>On 4 February 2013 11:17, Tim Delaney <span dir="ltr"><<a href="mailto:timothy.c.delaney@gmail.com" target="_blank">timothy.c.delaney@gmail.com</a>></span> wrote:<br>


</div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>On 4 February 2013 10:53, João Bernardo <span dir="ltr"><<a href="mailto:jbvsmo@gmail.com" target="_blank">jbvsmo@gmail.com</a>></span> wrote:<br>



</div><div class="gmail_extra"><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">




<div dir="ltr"><div><div><div><div><div><div>Particularly It would be nice to have custom attributes and methods besides the value and the name.<br></div>





</div></div></div></div></div></div></blockquote></div></div></div></div></blockquote><div><br></div></div></div><div>I've also made it so that you can override the metaclass to return a subclass of EnumValue.</div>


<div><br></div></div></div></div></blockquote></div></div><div>Can you elaborate on the utility of this feature? What realistic use cases do you see for it? I think that at this point it's important to weigh all benefits of features vs. implementation complexity, and there's absolutely no need to support every feature every other enum implementation has. I want to stress again that the most important characteristic of your implementation is the clean syntax which means that enums are so easy to define they don't really need special Python syntax and a library feature can do. However, there's a big leap from this to defining custom metaclasses for enums.</div>
</div></div></div></blockquote><div><br></div><div style>The custom metaclass is purely a mechanism to make it easy to use a custom class for the enum value. It wold be possible to manually assign a custom enum type to each enum, but then you wold lose the ability to just define the names. By using a custom metaclass, you can have it automatically assign the enum value type that you want.</div>
<div style><br></div><div style>My next email specifies a simplified syntax for specifying the custom metaclass (you don't need to create one at all).</div><div style><br></div><div style>Supporting this functionality was actually very simple. However, I am wondering though how useful this is without being able to specify additional parameters for the enums. I've often used enums with quite complex behaviour (e.g. in java) - the enum part is purely to have a unique value assigned to each instance of the class and not repeating myself for no good reason. I couldn't quite do the same with this as it currently is - whilst I can have whatever behaviour I want, there's nothing to key it off except the name and value which probably isn't enough. I've been trying to think of a syntax which would work to pass additional parameters and I can't think of anything cleaner than having a specialised class to pass the additional parameters - but I need to somehow be able to specify the optional integer value of the enum. Maybe have the first parameter be None?</div>
<div style><br></div><div style>class EnumParams():</div><div style>    def __init__(self, value=None, *p, **kw):</div><div style>        self.value = value</div><div style>        ....</div><div style><br></div><div style>
    def _resolve_proxies(self):</div><div style>        # names would have been affected by EnumValues.__getattr__ - need to resolve them from _EnumProxy to the actual values</div><div style><br></div><div style>...</div>
<div style><br></div><div style>class MyEnumValue(EnumValue):<br>    def __new__(cls, key, value, *p):</div><div style>        e = super().__new__(cls, key, value)</div><div style>        e.p = p</div><div style><br></div>
<div style>    def dump(self):</div><div style>        print(self.p)</div><div style><br></div><div style>class MyEnum(Enum, metaclass=Enum.subtype(MyEnumValue)):</div><div style>    A = EnumParams(None, 'extra', 'params')</div>
<div style>    B = EnumParams(3, 'more', 'params')</div><div style><br></div><div style>Thoughts? Is the extra complexity worth it? The thing is, this doesn't take away from the ability to specify the very simple clean enums - but it would give the enums pretty much the full capabilities of java enums.</div>
<div style><div style><div><br></div></div><div style>I'd like to have all these features available so that any PEP could reference them and discuss the pros and cons (including how well they work in practice).</div><div>
<br></div></div><div style>Tim Delaney</div></div></div></div>