<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Sep 22, 2013 at 4:52 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><a href="http://bugs.python.org/issue19011" target="_blank">http://bugs.python.org/<u></u>issue19011</a><br>
<br>
So, as anyone who has worked with Enum is probably aware by now, Enum's are a strange duck -- you might even call them platypuses.<br>
<br>
For example, Enum members are instances of the class, but they are defined inside the class structure, and new ones cannot be created afterwards; Enum classes also support iteration and containment checks.<br>
<br>
What I'm looking for feedback on is the question is #19011: should an Enum member be considered a class level attribute?<br>
<br>
On the one hand, they are defined inside the class, and they are accessed via dot notation (EnumClass.member).<br>
<br>
On the other hand, inside the class they look like 3 and 5 and 'up' and 'east', and they don't live in the class dictionary.<br>
<br>
Also, if we change Enum so that members do act more like class attributes, then things like Color.red.blue.green.blue will result in Color.blue, and that seems stranger to me than having class instances be available on the class without be full-fledged class-attributes.<br>



<br>
Thoughts?  Opinions?  Pearls of wisdom?<br></blockquote></div><br></div><div class="gmail_extra">I wouldn't lose much sleep over this. Classes can override __getattribute__ so that instance variables appear to exist even though they are not in the instance's __dict__. It's the same for metaclasses.<br>

<br></div><div class="gmail_extra">As for attributes appearing different inside the class than when accessed as an attribute, that's not unusual -- descriptors can legitimately do that. It was more common in Python 2, where this applied to all unbound methods, but even in Python 3 it applies to static and class methods.<br>

<br></div><div class="gmail_extra">I would draw the line at being able to access members as attributes of other members. Making Color.red.blue be a spelling for Color.blue feels like an abomination. If you can make dir(Color) return the strings 'red', 'blue' etc. in addition to other class attributes without making Color.red.blue work, go for it. If you can't, that's fine too. Users should (obviously) steer clear from relying on either behavior.<br clear="all">


</div><div class="gmail_extra"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)
</div></div>