<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 23, 2013 at 6:45 AM, Chris Lambacher <span dir="ltr"><<a href="mailto:chris@kateandchris.net" target="_blank">chris@kateandchris.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote"><div class="im">On Sun, Sep 22, 2013 at 10:41 PM, Zero Piraeus <span dir="ltr"><<a href="mailto:z@etiol.net" target="_blank">z@etiol.net</a>></span> wrote:<br>
<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 style="overflow:hidden">I may be misunderstanding the use case given in the issue,</div></blockquote><div><br></div></div><div>To clarify the use case, since it is my bug, this is so that the enum values are always available for comparison. The exact use case is in Django templates where a value comes from the database. If you want to compare you either have to use __class__ which I would say is a code smell, or you have to provide the Enum class. The code we are using for this is open source <a href="http://github.com/tindie/django-tidyenum" target="_blank">http://github.com/tindie/django-tidyenum</a>. An example of how this will be used in practice is:</div>
<div><br></div><div> {% if object.state == object.state.completed %}</div><div> some html</div><div> {% endif %}</div></div></div></div></blockquote><div><br></div><div>Now I see your use case. But I disagree that the best solution is to allow accessing the enum values as attributes on object.state -- I would recommend using __class__ to make it clear to the reader what's going on, or to add the right Enum subclass to your template parameters. Tbe expression you show in your example here will just baffle most readers who haven't thought deeply about the issue.<br>
<br></div><div>(How would you compare a value that is a timedelta with a known timedelta? You'd have to import the datetime module or use __class__, right?)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="im"><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 style="overflow:hidden"> but it seems<br>
to me that having to use<br>
<br>
Color.red.__class__.blue<br>
<br>
(what is being complained about in the issue), while not exactly pretty,<br>
makes a lot more semantic sense than<br>
<br>
Color.red.blue<br>
<br>
... which is just bizarre.</div></blockquote></div></div><br>Any more bizarre than any other class that has properties of it's own type?</div></div></blockquote><div><br></div><div>Yes, because you rarely if ever see them accessed that way.<br>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"> a = 0</div><div class="gmail_extra">
a.real.numerator.real.numerator<br clear="all"></div></div></blockquote><div><br></div><div>But that's different! Each of the attributes here (.real, .numerator) is defined as an instance attribute.<br></div><div>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><div>It is only weird because we are not used to seeing classes where the properties are instances of the class. I am not a core developer, but I have been programming in Python for more than 10 years, and I (and the other similarly experienced developers I work with) found that not having access to the class level properties was weird (yes I am aware that they are not actually class level properties but everywhere else Enum works hard to make it look like they are. See for instance the __dir__ method: <a href="http://hg.python.org/cpython/file/ed011b0d7daf/Lib/enum.py#l242" target="_blank">http://hg.python.org/cpython/file/ed011b0d7daf/Lib/enum.py#l242</a>).</div>
</div></div></blockquote><div><br></div><div>Sorry to burst your bubble, but there is no rule that because you can access something on the class you should be able to access it on the instance. Try asking an instance for its class's __mro__ or __bases__.<br>
</div><div> </div></div>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div></div>